Documentation
¶
Overview ¶
Package dbmigrate runs ordered, one-way schema steps against the SQLite database. A one-row schema_version table records how many steps have been applied; each pending step runs in its own transaction, so a failure leaves the database at the last step that completed. Before the first pending step on a database that holds data, the database is copied aside.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDanglingForeignKey = errors.New("foreign key check failed: a row points at nothing")
ErrDanglingForeignKey is returned when a step leaves a row pointing at nothing.
var ErrNewerDatabase = errors.New("database is newer than this release")
ErrNewerDatabase is returned when the database was migrated by a newer release.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result struct {
// Applied is how many steps ran this start.
Applied int
// BackupPath is the copy taken before the first step, empty when none was needed.
BackupPath string
}
Result says what Run did.
func Run ¶
func Run(ctx context.Context, db *sql.DB, dbPath string, steps []Step, log *slog.Logger) (Result, error)
Run brings the database up to len(steps). A database with no tables at all is fresh: it is stamped as current without running anything, because the stores create their tables in the newest shape. A database stamped with more steps than this binary knows is refused, since an older binary must not guess at a newer schema.