Documentation
¶
Overview ¶
Package migrations implements offline, forward-only metadata upgrades.
Index ¶
Constants ¶
const DefaultBatchSize = 1000
Variables ¶
var ( ErrEmptyRegistry = errors.New("metadata migration registry is empty") ErrInvalidRegistry = errors.New("invalid metadata migration registry") ErrChecksumDrift = errors.New("metadata migration checksum changed") ErrNewerSchema = errors.New("metadata schema is newer than this binary") ErrLegacySchema = errors.New("unsupported unversioned metadata schema") )
Functions ¶
This section is empty.
Types ¶
type Backfill ¶
type Backfill func(context.Context, Batch) (BatchResult, error)
Backfill executes at most Batch.Limit rows. Runner commits its data changes and returned cursor in the same transaction.
type Batch ¶
type Batch struct {
Tx *sql.Tx
Cursor string
Limit int
// Rebind converts ? placeholders to the dialect's own form. It is never
// nil; the runner substitutes an identity function for dialects that take
// ? directly.
Rebind func(string) string
}
Batch is one resumable backfill transaction.
type BatchResult ¶
BatchResult describes the durable checkpoint after a backfill batch.
type Locker ¶
Locker serializes migration runners. Advisory implementations must use the supplied connection so lock ownership lasts until release.
func NewAdvisoryLocker ¶
NewAdvisoryLocker returns a connection-owned PostgreSQL or MySQL lock.
func NewFileLocker ¶
NewFileLocker returns the cross-process lock used by file-backed SQLite.
func NewProcessLocker ¶
func NewProcessLocker() Locker
NewProcessLocker returns a process-wide lock suitable for isolated in-memory SQLite databases.
type Migration ¶
type Migration struct {
Version int
Name string
BackfillRevision string
SQL map[string]SQL
Backfill Backfill
BatchSize int
}
Migration is immutable after release. BackfillRevision must change whenever the Go backfill behavior changes.
func MySQLRegistry ¶
func PostgresRegistry ¶
PostgresRegistry and MySQLRegistry expose the same v1alpha1 schema contract with backend-native type and identity syntax. Keeping the migration registry shared prevents the three providers from drifting at the schema boundary while allowing each engine to execute its own DDL.
func SQLiteRegistry ¶
SQLiteRegistry returns the checked-in SQLite migration registry.
type Phase ¶
type Phase string
Phase identifies the durable point at which an interrupted upgrade resumes.
type Runner ¶
type Runner struct {
DB *sql.DB
Dialect string
Registry []Migration
Locker Locker
Logger *slog.Logger
Now func() time.Time
// Rebind converts ? placeholders to the dialect's own form for data-driven
// backfills. Leave nil to use the runner's own Dialect-derived rebinder;
// an identity default would feed ? straight to a dialect that rejects it.
Rebind func(string) string
}
type UpgradeError ¶
UpgradeError identifies the exact migration phase that blocked readiness.
func (*UpgradeError) Error ¶
func (e *UpgradeError) Error() string
func (*UpgradeError) Unwrap ¶
func (e *UpgradeError) Unwrap() error