migrations

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatusFailed   = Status{"failed"}
	StatusFinished = Status{"finished"}
)
View Source
var (
	ErrStateNotFound  = errors.New("state not found")
	ErrStatusNotFound = errors.New("status not found")
)

Functions

This section is empty.

Types

type Migration

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

func MustNewMigration

func MustNewMigration(name string, fn MigrationFunc) Migration

func NewMigration

func NewMigration(name string, fn MigrationFunc) (Migration, error)

func (Migration) Fn

func (m Migration) Fn() MigrationFunc

func (Migration) IsZero

func (m Migration) IsZero() bool

func (Migration) Name

func (m Migration) Name() string

type MigrationFunc

type MigrationFunc func(ctx context.Context, state State, saveStateFunc SaveStateFunc) error

MigrationFunc is executed with the previously saved state. If the migration func is executed for the first time then the saved state will be an empty map. State is saved by calling the provided function. If a migration function returns an error it will be executed again. If a function doesn't return an error it should not be executed again.

type Migrations

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

func MustNewMigrations

func MustNewMigrations(migrations []Migration) Migrations

func NewMigrations

func NewMigrations(migrations []Migration) (Migrations, error)

func (Migrations) Count

func (m Migrations) Count() int

func (Migrations) List

func (m Migrations) List() []Migration

type ProgressCallback

type ProgressCallback interface {
	// OnRunning is only called when a migration is actually being executed.
	OnRunning(migrationIndex int, migrationsCount int)

	// OnError is called when the migration process for one of the migrations
	// fails with an error.
	OnError(migrationIndex int, migrationsCount int, err error)

	// OnDone is always called once all migrations were successfully executed
	// even if no migrations were run.
	OnDone(migrationsCount int)
}

type Runner

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

func NewRunner

func NewRunner(storage Storage, logger logging.Logger) *Runner

func (Runner) Run

func (r Runner) Run(ctx context.Context, migrations Migrations, callback ProgressCallback) error

type SaveStateFunc

type SaveStateFunc func(state State) error

type State

type State map[string]string

type Status

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

type Storage

type Storage interface {
	// LoadState returns ErrStateNotFound if state has not been saved yet.
	LoadState(name string) (State, error)
	SaveState(name string, state State) error

	// LoadStatus returns ErrStatusNotFound if status has not been saved yet.
	LoadStatus(name string) (Status, error)
	SaveStatus(name string, status Status) error
}

Jump to

Keyboard shortcuts

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