Documentation
¶
Overview ¶
Package migrate runs the embedded SQL migrations in order, idempotently.
Migrations live in /migrations as numbered .sql files. They are embedded into the chalkd binary and applied at startup (or via `chalkd --migrate-only`, added in phase 12). Each migration runs inside its own transaction; a schema_migrations table records what's been applied.
Migrations are forward-only. Down migrations are not provided; if a rollback is needed, restore from a Postgres snapshot. This is a deliberate choice: down migrations are routinely wrong, especially for data-bearing changes, and the project doesn't need them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoMigrations = errors.New("no migrations found")
ErrNoMigrations is returned when the embedded fs is empty.
Functions ¶
This section is empty.
Types ¶
type Migration ¶
type Migration struct {
// Version is the file's numeric prefix (e.g. "0001"). Sortable lexicographically.
Version string
// Name is the descriptive part of the filename (e.g. "init").
Name string
// SQL is the entire file contents.
SQL string
}
Migration represents a single SQL file to apply.
func Load ¶
Load parses the supplied filesystem into an ordered slice of migrations. Files must be named like "NNNN_description.sql" (e.g. "0001_init.sql"). Files not matching this pattern are ignored with no error, allowing README.md or .gitkeep to live alongside.
fsys is typically the package-level embed.FS exposed by package chalk (it satisfies io/fs.FS), but any io/fs.FS works -- handy for unit tests.