Documentation
¶
Overview ¶
Package migrate wraps goose with the safety rules this database needs.
The hazard being guarded against is specific and expensive. Production already carries all 102 tables of migration 00001, created by drizzle and tracked in drizzle.__drizzle_migrations. Goose knows nothing about that ledger, so a plain `goose up` against production would try to CREATE TABLE over a live 285 GB schema. Everything here exists to make that impossible rather than merely discouraged.
Index ¶
Constants ¶
const BaselineVersion int64 = 1
BaselineVersion is the migration that captures the pre-existing schema. Any database that already has the schema must have exactly this version stamped, never executed.
Variables ¶
var ErrAlreadyBaselined = errors.New("database already has a goose ledger")
ErrAlreadyBaselined is returned when baselining a database that goose already tracks, which would otherwise silently rewrite history.
var ErrEmptySchema = errors.New("database has no existing schema to baseline")
ErrEmptySchema is returned when baselining a database with no schema. Stamping there would permanently skip table creation and leave an unusable database.
var ErrNeedsBaseline = errors.New("database has an existing schema but no goose ledger")
ErrNeedsBaseline is returned when a database already contains the schema but has no goose ledger. Applying migrations in that state would attempt to recreate live tables.
Functions ¶
func Apply ¶
Apply runs every pending migration. It refuses when the database has a schema but no ledger, because that is the production shape and applying there would try to recreate live tables.
func Baseline ¶
Baseline stamps the baseline version as applied without executing it, which is how a database that already has the schema joins goose's history.
It refuses on an empty database: stamping there would skip table creation forever and leave a database that can never be migrated into a working state.
Types ¶
type Migration ¶
type Migration struct {
Version int64 `json:"version"`
Source string `json:"source"`
Applied bool `json:"applied"`
At time.Time `json:"applied_at,omitzero"`
}
Migration is one entry in a migration plan.
type State ¶
type State struct {
HasLedger bool `json:"has_ledger"`
HasSchema bool `json:"has_schema"`
TableCount int `json:"table_count"`
DBVersion int64 `json:"db_version"`
Migrations []Migration `json:"migrations"`
NeedsBaselin bool `json:"needs_baseline"`
}
State describes what goose knows about a database versus what exists on disk.