migrate

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: PostgreSQL Imports: 15 Imported by: 0

Documentation

Overview

Package migrate provides a mechanism for arbitrary migration operations that should block startup, such as moving Etcd objects from one key to another. IMPORTANT: migrations _must_ be written to be idempotent, and we should prefer non-destructive updates in order to allow rollbacks.

server/internal/migrate/store.go

Index

Constants

View Source
const ElectionName = election.Name("migration_runner")
View Source
const LockTTL time.Duration = 30 * time.Second

Variables

This section is empty.

Functions

func Provide

func Provide(i *do.Injector)

Provide registers migration dependencies with the injector.

Types

type Migration

type Migration interface {
	// Identifier returns a unique semantic name for this migration.
	Identifier() string
	// Run executes the migration using dependencies from the injector.
	// The context should be used for cancellation and timeouts.
	Run(ctx context.Context, i *do.Injector) error
}

Migration defines the interface for data migrations.

func AllMigrations

func AllMigrations() ([]Migration, error)

AllMigrations returns the ordered list of migrations. Order matters - migrations are executed in slice order. Add new migrations to this list in chronological order.

type ResultStore

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

func NewResultStore

func NewResultStore(client *clientv3.Client, root string) *ResultStore

func (*ResultStore) Get

func (s *ResultStore) Get(identifier string) storage.GetOp[*StoredResult]

func (*ResultStore) Key

func (s *ResultStore) Key(identifier string) string

func (*ResultStore) Prefix

func (s *ResultStore) Prefix() string

func (*ResultStore) Put

type RevisionStore

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

func NewRevisionStore

func NewRevisionStore(client *clientv3.Client, root string) *RevisionStore

func (*RevisionStore) Create

func (*RevisionStore) Get

func (*RevisionStore) Key

func (s *RevisionStore) Key() string

func (*RevisionStore) Update

func (*RevisionStore) Watch

type Runner

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

Runner orchestrates migration execution with distributed locking.

func NewRunner

func NewRunner(
	hostID string,
	store *Store,
	injector *do.Injector,
	loggerFactory *logging.Factory,
	migrations []Migration,
	candidate *election.Candidate,
) *Runner

NewRunner creates a new migration runner.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) error

Run executes any pending migrations if this runner wins the election, otherwise waits until the current revision reaches its target.

type Store

type Store struct {
	Revision *RevisionStore
	Result   *ResultStore
}

Store wraps all migration-related stores.

func NewStore

func NewStore(client *clientv3.Client, root string) *Store

NewStore creates a new composite migration store.

type StoredResult

type StoredResult struct {
	storage.StoredValue
	Identifier       string        `json:"identifier"`
	Successful       bool          `json:"successful"`
	StartedAt        time.Time     `json:"started_at"`
	CompletedAt      time.Time     `json:"completed_at"`
	RunByHostID      string        `json:"run_by_host_id"`
	RunByVersionInfo *version.Info `json:"run_by_version_info"`
	Error            string        `json:"error,omitempty"`
}

StoredResult tracks the outcome of a specific migration.

type StoredRevision

type StoredRevision struct {
	storage.StoredValue
	Identifier string `json:"identifier"`
}

StoredRevision tracks the most recently applied migration.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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