Documentation
¶
Overview ¶
Package migrate provides a versioned schema migration engine for tapes storage backends.
Storage drivers construct a Migrator with NewMigrator, passing their own ordered list of Migration values (typically loaded via //go:embed from a migrations/ directory under the driver package). The engine tracks applied versions in a schema_migrations table with a UNIQUE constraint on version, and detects gaps to fail fast on corrupted state.
Postgres uses an advisory lock to serialize concurrent migrators; SQLite relies on its file-level lock.
Index ¶
Constants ¶
const ( // DialectPostgres identifies the PostgreSQL dialect. DialectPostgres = "postgres" // DialectSQLite identifies the SQLite dialect. DialectSQLite = "sqlite" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Migration ¶
type Migration struct {
// Version is the sequential migration number (1, 2, 3, ...).
Version int
// Description is a human-readable summary of the migration.
Description string
// Up is the SQL to apply for this migration.
// The SQL is dialect-specific — each driver supplies its own migrations
// so the engine does not need to branch on dialect for the SQL itself.
Up string
}
Migration represents a single versioned schema migration.
func MigrationsFromFS ¶
MigrationsFromFS reads all .sql files from an fs.FS (typically produced by //go:embed) and returns an ordered slice of Migration values.
File names must follow the pattern "NNN_description.sql" where NNN is a zero-padded integer version (e.g. "001_baseline_schema.sql"). Files that don't match this pattern are silently skipped.
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator applies an ordered set of migrations to a database. Create one with NewMigrator.
func NewMigrator ¶
NewMigrator creates a Migrator for the given database, dialect, and ordered migration list. The dialect must be DialectPostgres or DialectSQLite; unknown dialects are rejected immediately.
Migrations are sorted by version internally. Callers should supply them in order, but the constructor enforces sorting for safety.