migration

package
v1.17.2-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: BSD-3-Clause Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrItemIDShouldntChange = errors.New("item.ID shouldn't be changing after update")

Functions

func LatestVersion

func LatestVersion(sm Steps) uint64

LatestVersion returns latest version from supplied migration steps.

func Migrate

func Migrate(s storage.BatchedStore, sm Steps) error

Migrate migrates the storage to the latest version

func ValidateVersions

func ValidateVersions(sm Steps) error

ValidateVersions checks versions if they are in order n (where n min version value), n+1, n+2, n+3... (all values are increasing orders)

func Version

func Version(s storage.Store) (uint64, error)

Version returns the current version of the storage

func WithItemDeleteFn

func WithItemDeleteFn(fn ItemDeleteFn) option

WithItemDeleteFn return option with ItemDeleteFn set.

func WithItemUpdaterFn

func WithItemUpdaterFn(fn ItemUpdateFn) option

WithItemUpdaterFn return option with ItemUpdateFn set.

Types

type ItemDeleteFn

type ItemDeleteFn func(storage.Item) (deleted bool)

ItemDeleteFn is callback function called in migration step to check if Item should be removed in this step.

type ItemUpdateFn

type ItemUpdateFn func(storage.Item) (updatedItem storage.Item, hasChanged bool)

ItemUpdateFn is callback function called in migration step to check if Item should be updated in this step.

type StepFn

type StepFn func(storage.BatchedStore) error

StepFn is a function that migrates the storage to the next version

func NewStepOnIndex

func NewStepOnIndex(query storage.Query, opts ...option) StepFn

NewStepOnIndex creates new migration step with update and/or delete operation. Migration will iterate on all elements selected by query and delete or update items based on supplied callback functions.

func NewStepsChain

func NewStepsChain(steps ...StepFn) StepFn

NewStepsChain returns new StepFn which combines all supplied StepFn into single StepFn.

type Steps

type Steps = map[uint64]StepFn

Steps is a map of versions and their migration functions

type StorageVersionItem

type StorageVersionItem struct {
	Version uint64
}

func (*StorageVersionItem) Clone

func (s *StorageVersionItem) Clone() storage.Item

Clone implements the storage.Item interface.

func (*StorageVersionItem) ID

func (s *StorageVersionItem) ID() string

ID implements the storage.Item interface.

func (*StorageVersionItem) Marshal

func (s *StorageVersionItem) Marshal() ([]byte, error)

Marshal implements the storage.Item interface.

func (StorageVersionItem) Namespace

func (s StorageVersionItem) Namespace() string

Namespace implements the storage.Item interface.

func (StorageVersionItem) String

func (s StorageVersionItem) String() string

Clone implements the storage.Item interface.

func (*StorageVersionItem) Unmarshal

func (s *StorageVersionItem) Unmarshal(bytes []byte) error

Unmarshal implements the storage.Item interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL