Versions in this module Expand all Collapse all v0 v0.1.0 Sep 30, 2026 Changes in this version + var ErrChecksumMismatch = errors.New("xmigrator: checksum mismatch") + var ErrCommitOutcomeUnknown = errors.New("xmigrator: commit outcome unknown") + var ErrDefinitionMismatch = errors.New("xmigrator: definition mismatch") + var ErrDropScope = errors.New("xmigrator: invalid drop scope") + var ErrForeignKey = errors.New("xmigrator: foreign key violation") + var ErrHistoryConflict = errors.New("xmigrator: history precondition failed") + var ErrHookMismatch = errors.New("xmigrator: hook mismatch") + var ErrInvalidConfig = errors.New("xmigrator: invalid configuration") + var ErrInvalidSource = errors.New("xmigrator: invalid source") + var ErrInvalidSteps = errors.New("xmigrator: invalid steps") + var ErrIrreversible = errors.New("xmigrator: irreversible migration") + var ErrMetadataConflict = errors.New("xmigrator: metadata conflict") + var ErrMetadataVersion = errors.New("xmigrator: unsupported metadata version") + var ErrNotApplied = errors.New("xmigrator: migration not applied") + var ErrUnknownApplied = errors.New("xmigrator: unknown applied migration") + var ErrUnsafeSQL = errors.New("xmigrator: unsafe SQL") + var ErrVersionExists = errors.New("xmigrator: version exists") + func ValidateSQL(s Script, dialect string) error + type Action struct + Direction Direction + Name string + OutOfOrder bool + Version Version + type ChecksumPolicy uint8 + const ChecksumDisabled + const ChecksumStrict + const ChecksumWarn + type CreateOptions struct + Dir string + Name string + Now func() time.Time + Version Version + type CreatedFiles struct + Down string + Up string + Version Version + func Create(ctx context.Context, o CreateOptions) (CreatedFiles, error) + type Direction string + const Down + const Up + type DownDefinition struct + Checksum [32]byte + HookRevision string + Kind DownKind + type DownKind string + const DownIrreversible + const DownNoop + const DownSQL + type Driver interface + ReadHistorySnapshot func(context.Context) ([]Record, error) + ValidateScript func(Script) error + WithSession func(context.Context, func(Session[T]) error) error + type Hooks struct + AfterDown func(context.Context, T) error + AfterUp func(context.Context, T) error + BeforeDown func(context.Context, T) error + BeforeUp func(context.Context, T) error + DownRevision string + UpRevision string + type Issue struct + Direction Direction + Kind string + Version Version + type Logger interface + Debugw func(string, ...any) + Errorw func(string, ...any) + Infow func(string, ...any) + Warnw func(string, ...any) + func NewSlogLogger(l *slog.Logger) Logger + type Migration struct + Down Script + Name string + Up Script + Version Version + type MigrationError struct + Direction Direction + Err error + Name string + Stage string + Version Version + func (e *MigrationError) Error() string + func (e *MigrationError) Unwrap() error + type MigrationStatus struct + ApplyOrder int64 + ChecksumState string + DownKind DownKind + Name string + OutOfOrder bool + State string + Version Version + type Migrator struct + func New[T any](s Source, d Driver[T], opts ...Option[T]) (*Migrator[T], error) + func (m *Migrator[T]) Down(ctx context.Context, steps int) (Result, error) + func (m *Migrator[T]) DownAll(ctx context.Context) (Result, error) + func (m *Migrator[T]) Drop(ctx context.Context) error + func (m *Migrator[T]) PlanRepairDown(ctx context.Context, v Version) (RepairPlan, error) + func (m *Migrator[T]) RepairDown(ctx context.Context, v Version) (out RepairResult, err error) + func (m *Migrator[T]) Status(ctx context.Context) (Status, error) + func (m *Migrator[T]) Up(ctx context.Context, steps int) (Result, error) + type Option func(*Migrator[T]) error + func WithChecksumPolicy[T any](p ChecksumPolicy) Option[T] + func WithHooks[T any](hooks map[Version]Hooks[T]) Option[T] + func WithLogger[T any](l Logger) Option[T] + func WithUnknownAppliedPolicy[T any](p UnknownAppliedPolicy) Option[T] + type Record struct + AppliedAt time.Time + ApplyOrder int64 + DownChecksum [32]byte + DownHookRevision string + DownKind DownKind + Name string + UpChecksum [32]byte + UpHookRevision string + Version Version + func (r Record) DownDefinition() DownDefinition + type RepairPlan struct + After DownDefinition + Before DownDefinition + Issues []Issue + Version Version + WouldChange bool + type RepairResult struct + After DownDefinition + Before DownDefinition + Changed bool + Confirmed bool + Issues []Issue + Version Version + type Result struct + Actions []Action + Direction Direction + Issues []Issue + type Script struct + Checksum [32]byte + ForeignKeys *bool + HookRevision string + Kind DownKind + SQL string + func (s Script) DownDefinition() DownDefinition + type Session interface + Drop func(context.Context) error + EnsureMetadata func(context.Context) error + InTx func(context.Context, Script, func(Transaction[T]) error) (TxOutcome, error) + ReadExistingHistory func(context.Context) ([]Record, error) + ReadHistory func(context.Context) ([]Record, error) + type Source struct + func NewSource(files fs.FS, dir string, options ...SourceOption) (Source, error) + func (s Source) Dialect() string + func (s Source) Snapshot(ctx context.Context) ([]Migration, error) + func (s Source) WithDialect(dialect string) (Source, error) + type SourceError struct + Err error + File string + Version Version + func (e *SourceError) Error() string + func (e *SourceError) Unwrap() error + type SourceOption func(*Source) error + func WithDialect(dialect string) SourceOption + type Status struct + Issues []Issue + Migrations []MigrationStatus + type Transaction interface + Delete func(context.Context, Version) error + ExecScript func(context.Context, Script) error + Executor func() T + Insert func(context.Context, Record) error + ReadHistory func(context.Context) ([]Record, error) + UpdateDownMetadata func(context.Context, Version, DownDefinition) error + type TxOutcome uint8 + const TxCommitted + const TxNotCommitted + const TxUnknown + type UnknownAppliedPolicy uint8 + const UnknownAppliedAllow + const UnknownAppliedError + type ValidationReport struct + Migrations int + func Validate(ctx context.Context, s Source) (ValidationReport, error) + type Version int64