Expand description
Versioned, embedded schema migrations for headgate’s SQL backends.
The migration history is data, not a guess made from whichever columns happen to exist. Every applied version records the SHA-256 of its immutable up SQL. A changed historical migration therefore fails validation instead of silently turning two installations at “version 1” into different schemas.
Postgres applies each version and its history row in one transaction. MySQL DDL commits implicitly, so its migrations must be resumable: a connection-scoped lock serializes migrators, every statement in an up migration is idempotent, and the version row is written only after the resulting schema passes the current manifest.
Structs§
- Applied
Migration - Migrate
Options - Migrate
Result - Migration
- A checked-in migration. Existing versions are immutable: add a new version instead of editing an applied one, even when the edit appears additive.
- Migration
Step - Mysql
Validation - Postgres
Namespace - Postgres
Validation
Enums§
- Backend
- The two stores with durable schemas. Redis key layouts are versioned by code and Lua, not by a DDL migrator, so claiming a Redis migration backend would be dishonest.
- Direction
- Installation
State - Migration
Error
Constants§
- DEFAULT_
MYSQL_ LOCK_ NAMESPACE - Backward-compatible with the lock name shipped before namespaces were configurable.
Functions§
- adopt_
mysql - adopt_
mysql_ with_ lock_ namespace - adopt_
postgres - adopt_
postgres_ in_ schema - applied_
mysql - applied_
postgres - applied_
postgres_ in_ schema - checksum
- The checksum stored in
headgate_schema_migration. It covers the UP SQL because that is the schema an applied version claims was installed; changing DOWN SQL is caught by source parity tests and review, while it cannot make an existing schema differ. - latest_
version - migrate_
mysql - migrate_
mysql_ with_ lock_ namespace - migrate_
postgres - migrate_
postgres_ in_ schema - migration
- migrations
- mysql_
migration_ lock_ name - Build the connection-scoped MySQL migration lock name. The readable form preserves
the historical
headgate:migrate:<database>default. Only an overlong database is hashed under a distinct:h:marker, keeping the result below MySQL’s 64-byte GET_LOCK limit without aliasing a short literal database name. - plan
- validate_
history - Validate history independently of a database. This is also the planner’s first step,
so a checksum mismatch cannot be bypassed with
--dry-runor a target version. - validate_
mysql - validate_
postgres - validate_
postgres_ in_ schema