migration

package
v0.296.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group[R any] struct {
	// ID field within the Group specifically denotes the intended domain or area, such as "foo-queue",
	// ensuring that migration steps within this group are uniquely identified and do not overlap
	// or interfere with migrations from other namespaces.
	ID string
	// Steps field is an ordered list of individual migration actions,
	// each capable of migrating up or down (applying or rolling back changes).
	// The generic type parameter `R` allows the migration steps to work with a shared resource,
	// which could be something like a live database connection or a transaction object.
	// This design provides flexibility and consistency,
	// ensuring that all steps in a given migration group have access to necessary shared resources.
	Steps []Step[R]
}

Group represents a coherent collection of migration steps associated with a specific topic or namespace. This struct serves as a means to encapsulate a set of migration steps that should be executed together or within the context of a designated topic.

type Migratable

type Migratable interface {
	Migrate(context.Context) error
}

type Migrator added in v0.238.0

type Migrator[R resourceConnection] struct {
	// Resource is the ResourceConnection where the migration steps needs to operate.
	Resource R
	// Namespace field denotes the intended domain or area, such as "foo-repository",
	// ensuring that migration steps are uniquely identified
	// and do not interfere with migrations from other namespaces.
	Namespace string
	// Steps field is an ordered list of individual migration actions,
	// each capable of migrating up or down (applying or rolling back changes).
	// The generic type parameter `R` allows the migration steps to work with a shared resource,
	// which could be something like a live database connection or a transaction object.
	// This design provides flexibility and consistency,
	// ensuring that all steps in a given migration group have access to necessary shared resources.
	Steps Steps[R]
	// StateRepository is the crud resource that contains the state of the migration steps.
	// The state repository doesn't have to be the same as the actual resource which is being managed.
	StateRepository StateRepository
	// EnsureStateRepository is an optional field that is guaranteed to be called before each migration.
	// If your StateRepository is not needing this, because it creates itself upon interaction,
	// then just leave this unset.
	//
	// EnsureStateRepository should be an idempotent function,
	// calling it multiple times should result at the same final state.
	EnsureStateRepository func(context.Context) error
}

func (Migrator[R]) Migrate added in v0.238.0

func (m Migrator[R]) Migrate(ctx context.Context) (rErr error)

type State added in v0.238.0

type State struct {
	ID StateID `ext:"id"`
	// Dirty will tells if the given migration step's state
	Dirty bool
}

State is the representation of a migration Step's outcome.

type StateID added in v0.238.0

type StateID struct {
	Namespace string
	Version   Version
}

type StateRepository added in v0.238.0

type Step

type Step[R any] interface {
	// MigrateUp applies the specific migration action associated with this step.
	// It is assumed that this step has not been executed prior to this invocation.
	//
	// Upon failure, it is up to the Migrator to undo the resources changes
	MigrateUp(R, context.Context) error
	// MigrateDown reverses the changes made by the corresponding MigrateUp action.
	// It is assumed that MigrateUp was successfully executed before calling this method.
	MigrateDown(R, context.Context) error
}

Step defines the behavior for an individual migration action.

R is a type parameter signifying a shared resource used across multiple migration steps. For instance, R could represent a live database connection or a transactional context.

type Steps added in v0.238.0

type Steps[R any] map[Version]Step[R]

Steps is a group of Migration Steps

type Version added in v0.238.0

type Version string

Version of the version identifier of a migration step. UNIX timestamp, or an incrementaly increasing integer values are often used for this purpose. The only constraint for a Version number that it must be sortable by string character comparison.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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