migration

package
v0.0.0-...-3979f71 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const StatusActivePrefix = "Active migration: "

StatusActivePrefix is the migration status prefix for the currently running migration.

View Source
const StatusComplete = "Migrations Complete"

StatusComplete is the migration status after the migration successfully completes.

View Source
const StatusErrorPrefix = "error during migration "

StatusErrorPrefix is the status message prefix when there is an error during the migration.

View Source
const StatusPending = "Migration pending"

StatusPending is the migration status before the migration has been started.

Variables

View Source
var ErrDuplicateID = errors.New("duplicate ID detected")

ErrDuplicateID is the error returned when the migration is given duplicate migration IDs.

View Source
var ErrUnorderedID = errors.New("migration IDs must be in ascending order")

ErrUnorderedID is the error returned when the migration is given migrations that aren't ordered correctly.

Functions

This section is empty.

Types

type Handler

type Handler func() error

Handler is the function which will be executed to perform the migration for this task.

type Migration

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

Migration manages the execution of multiple migration tasks and provides a mechanism for concurrent status checks.

func MakeMigration

func MakeMigration(migrationTasks []Task, logger *log.Logger) (*Migration, error)

MakeMigration initializes

func (*Migration) GetStatus

func (m *Migration) GetStatus() State

GetStatus returns the current status of the migration. This function is thread safe.

func (*Migration) RunMigrations

func (m *Migration) RunMigrations() chan struct{}

RunMigrations runs all tasks which have been loaded into the migration. It will update the status accordingly as the migration runs. RunMigrations immediately returns a channel which gets closed as soon as the last blocking migration finishes running.

type State

type State struct {
	// Time is when this state was captured.
	Time time.Time

	// Err is the last error which occurred during the migration. On an error the migration should halt.
	Err error

	// TaskID is the next task that should run, or -1 if all migrations are finished.
	TaskID int

	// Status is the most recent status message.
	Status string

	// Running indicates whether or not a migration is currently running.
	Running bool

	// Blocking indicates that one or more tasks have requested that the DB remain unavailable until they complete.
	Blocking bool
}

State is the current status of the migration.

func (State) IsZero

func (s State) IsZero() bool

IsZero returns true if the object has not been initialized.

type Task

type Task struct {
	// MigrationID is an internal ID that can be used by IndexerDb implementations.
	MigrationID int

	// Handler is the function which will be executed to perform the migration for this task.
	Handler Handler

	// DBUnavailable indicates whether or not queries should be blocked until this task is executed. If there are
	// multiple migrations the migration status should indicate that queries are blocked until all blocking tasks
	// have completed.
	DBUnavailable bool

	// Description should be a human readable description of what the migration does.
	Description string
}

Task is used to define a migration.

Jump to

Keyboard shortcuts

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