Documentation
¶
Index ¶
- func ChecksumContent(content string) string
- func ForceLockForTest(ctx context.Context, drv driver.Driver) error
- func ForceUnlockForTest(ctx context.Context, drv driver.Driver) error
- func WriteMigration(dir, name, upSQL, downSQL string) (string, error)
- type LintResult
- type Migration
- type MigrationState
- type MigrationStatus
- type Runner
- func (r *Runner) Dialect() string
- func (r *Runner) Down(ctx context.Context) error
- func (r *Runner) Lint(ctx context.Context) ([]LintResult, error)
- func (r *Runner) Pending(ctx context.Context) ([]Migration, error)
- func (r *Runner) Status(ctx context.Context) ([]MigrationStatus, error)
- func (r *Runner) Up(ctx context.Context) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChecksumContent ¶
ChecksumContent returns the SHA-256 hex digest of the given content string.
func ForceLockForTest ¶ added in v0.5.0
ForceLockForTest acquires the SQLite/libSQL sentinel lock out of band. Test-only.
func ForceUnlockForTest ¶ added in v0.5.0
ForceUnlockForTest releases the SQLite/libSQL sentinel lock. Test-only.
func WriteMigration ¶
WriteMigration creates a new migration file pair in the given directory. It returns the generated version string (timestamp in YYYYMMDDHHmmss format).
Types ¶
type LintResult ¶
LintResult reports a migration file whose content has changed after it was applied to the database.
type Migration ¶
Migration represents a single versioned migration with up and down SQL.
func ParseMigrationDir ¶
ParseMigrationDir reads a directory of migration files and returns them sorted by version. Files must follow the naming convention:
<version>_<name>.up.sql <version>_<name>.down.sql
If the directory does not exist, it returns nil with no error.
type MigrationState ¶
type MigrationState string
MigrationState indicates the lifecycle state of a migration.
const ( // StateApplied means the migration is in the directory and has been applied // with a matching checksum. StateApplied MigrationState = "applied" // StatePending means the migration is in the directory but has not been applied. StatePending MigrationState = "pending" // StateModified means the migration has been applied but the file content // no longer matches the stored checksum. StateModified MigrationState = "modified" // StateMissing means the migration was applied but the file no longer exists // in the migration directory. StateMissing MigrationState = "missing" )
type MigrationStatus ¶
type MigrationStatus struct {
Version string
Name string
State MigrationState
// Applied is true when the migration has been applied to the database,
// regardless of whether the file still matches. Kept for backward compatibility.
Applied bool
}
MigrationStatus represents the state of a single migration.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes migrations against a database using the driver interface.
func NewRunner ¶
NewRunner creates a Runner that reads migration files from dir and executes them against the provided driver. dialect ("postgres", "sqlite", or "libsql") selects the migration-lock strategy used by Up/Down.
func (*Runner) Dialect ¶ added in v0.5.0
Dialect returns the dialect string the Runner was constructed with.
func (*Runner) Lint ¶
func (r *Runner) Lint(ctx context.Context) ([]LintResult, error)
Lint checks all applied migrations for checksum mismatches, detecting files that were modified after being applied.
func (*Runner) Pending ¶ added in v0.5.0
Pending returns the migrations present in the directory that have not yet been applied to the database, in version order. It is the basis for `migrate check`: generating a new migration while unapplied files exist compounds snapshot drift, so callers should surface a clear error.