modelmigration

package
v0.0.0-...-0a82276 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseOperation

type BaseOperation struct{}

BaseOperation is a base implementation of the Operation interface. The rollback operation is a no-op by default.

func (*BaseOperation) Execute

func (b *BaseOperation) Execute(context.Context, description.Model) error

Execute returns not implemented. It is expected that the operation will override this method.

func (*BaseOperation) Rollback

func (b *BaseOperation) Rollback(context.Context, description.Model) error

Rollback is a no-op by default.

func (*BaseOperation) Setup

func (b *BaseOperation) Setup(Scope) error

Setup returns not implemented. It is expected that the operation will override this method.

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator is a collection of operations that can be performed as a single unit. This is not atomic, but it does allow for a rollback of the entire migration if any operation fails.

func NewCoordinator

func NewCoordinator(logger logger.Logger, operations ...Operation) *Coordinator

NewCoordinator creates a new migration coordinator with the given operations.

func (*Coordinator) Add

func (m *Coordinator) Add(operations Operation)

Add a new operation to the migration. It will be appended at the end of the list of operations.

func (*Coordinator) Len

func (m *Coordinator) Len() int

Len returns the number of operations in the migration.

func (*Coordinator) Perform

func (m *Coordinator) Perform(ctx context.Context, scope Scope, model description.Model) (err error)

Perform executes the migration. We log in addition to returning errors because the error is ultimately returned to the caller on the source, and we want them to be reflected in *this* controller's logs.

type Hook

type Hook func(Operation) error

Hook is a callback that is called after the operation is executed.

type Operation

type Operation interface {
	// Name returns the name of this operation.
	Name() string

	// Setup is called before the operation is executed. It should return an
	// error if the operation cannot be performed.
	Setup(Scope) error

	// Execute is called to perform the operation. It should return an error
	// if the operation fails.
	Execute(context.Context, description.Model) error

	// Rollback is called if the operation fails. It should attempt to undo
	// any changes made by the operation. This is best effort, and may not
	// always be possible.
	// Rollback should only be called on controller DB operations. The
	// model DB operations are not rolled back, but instead we remove the
	// db, clearing the model.
	Rollback(context.Context, description.Model) error
}

Operation is a single step in a migration. An operation plays its part in the model migration by being instructed as part of a model orchestration. The coordination is required as we need to perform transactions over multiple databases (controller and model). This is not atomic, but it does allow for a rollback of the entire migration if any operation fails.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope is a collection of database txn runners that can be used by the operations.

func NewScope

func NewScope(controllerDB, modelDB database.TxnRunnerFactory, modelDeleter database.DBDeleter) Scope

NewScope creates a new scope with the given database txn runners.

func (Scope) ControllerDB

func (s Scope) ControllerDB() database.TxnRunnerFactory

ControllerDB returns the database txn runner for the controller.

func (Scope) ModelDB

func (s Scope) ModelDB() database.TxnRunnerFactory

ModelDB returns the database txn runner for the model.

func (Scope) ModelDeleter

func (s Scope) ModelDeleter() database.DBDeleter

ModelDeleter returns the database deleter for the model.

type ScopeForModel

type ScopeForModel func(modelUUID model.UUID) Scope

ScopeForModel returns a Scope for the given model UUID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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