Skip to main content

Crate headgate_migrate

Crate headgate_migrate 

Source
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§

AppliedMigration
MigrateOptions
MigrateResult
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.
MigrationStep
MysqlValidation
PostgresNamespace
PostgresValidation

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
InstallationState
MigrationError

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-run or a target version.
validate_mysql
validate_postgres
validate_postgres_in_schema