Documentation
¶
Overview ¶
Package migrator orchestrates database migrations for contrib-backed services.
When loading from multiple directories or embedded filesystems, duplicate migration version+direction pairs are rejected instead of silently overriding one another. If commit acknowledgement is ambiguous after the SQL has executed, the runner records the migration as uncertain and blocks later runs until an operator reconciles the database state and migration record.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChecksumMismatchError ¶
ChecksumMismatchError reports that a migration's recorded checksum does not match the on-disk migration contents.
func (*ChecksumMismatchError) Error ¶
func (e *ChecksumMismatchError) Error() string
type Migration ¶
type Migration struct {
Version int64
Name string
Dir string // "up" or "down"
File string
SQL string
Checksum string
}
Migration is a versioned SQL change.
type Options ¶
type Options struct {
// MigrationsDir is kept for backward compatibility. If non-empty,
// it will be appended to MigrationsDirs.
MigrationsDir string
// MigrationsDirs allows loading migrations from multiple directories.
// Directories are processed in order and duplicate version+direction
// pairs are rejected when loading.
MigrationsDirs []string
// EmbeddedFSs allows loading migrations from multiple embedded
// filesystems. Each is expected to contain a "migrations" directory.
// Embedded filesystems are appended after explicit directories.
EmbeddedFSs []fs.FS
TableName string
LockKey int64
// LockTimeout bounds advisory lock acquisition. Zero keeps the default
// 10 minute timeout used by earlier versions.
LockTimeout time.Duration
// AllowDangerousDown enables Down(); keep disabled in API binaries.
AllowDangerousDown bool
// Logger outputs formatted status messages.
Logger func(format string, args ...any)
// UnlockFailureHandler observes advisory unlock failures without changing
// the primary migration result.
UnlockFailureHandler func(error)
}
Options configures the runner.
type Runner ¶
Runner executes SQL migrations transactionally and records state.
type UncertainMigrationError ¶ added in v2.1.0
UncertainMigrationError reports that a migration may have committed even though the runner could not confirm that outcome cleanly.
func (*UncertainMigrationError) Error ¶ added in v2.1.0
func (e *UncertainMigrationError) Error() string
func (*UncertainMigrationError) Unwrap ¶ added in v2.1.0
func (e *UncertainMigrationError) Unwrap() error
type UnresolvedMigrationStateError ¶ added in v2.1.0
type UnresolvedMigrationStateError struct {
Version int64
Name string
State string
TableName string
}
UnresolvedMigrationStateError reports that a prior migration run ended in a state that must be reconciled manually before the runner can continue.
func (*UnresolvedMigrationStateError) Error ¶ added in v2.1.0
func (e *UnresolvedMigrationStateError) Error() string