Documentation ¶
Index ¶
Constants ¶
const StatusActivePrefix = "Active migration: "
StatusActivePrefix is the migration status prefix for the currently running migration.
const StatusComplete = "Migrations Complete"
StatusComplete is the migration status after the migration successfully completes.
const StatusErrorPrefix = "error during migration "
StatusErrorPrefix is the status message prefix when there is an error during the migration.
const StatusPending = "Migration pending"
StatusPending is the migration status before the migration has been started.
Variables ¶
var ErrDuplicateID = errors.New("duplicate ID detected")
ErrDuplicateID is the error returned when the migration is given duplicate migration IDs.
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 ¶
MakeMigration initializes
func (*Migration) GetStatus ¶
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.
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 // 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.