- Rust:
headgate-migrate, including thehg-migratebinary. - Go:
github.com/mujhtech/headgate/go/headgatemigrate, including thego/headgatemigrate/cmd/hg-migratecommand.
Migration contract
headgate_schema_migration records a migration line, monotonically increasing version,
name, immutable SHA-256 checksum, and store-clock application time. Validation fails when:
- an applied version is missing, out of order, or newer than the binary;
- a historical migration’s name or bytes changed;
- the database is behind the embedded latest version; or
- a required table, column, index, trigger, state value, or saturation value is absent.
CLI
- Rust CLI
- Go CLI
HG_DATABASE_URL and DATABASE_URL are fallback environment variables. The backend is
inferred from postgres://, postgresql://, or mysql://; libpq keyword connection
strings and native MySQL DSNs require --backend.
Lock namespaces and schemas
PostgreSQL locks the installation’s qualified migration-history table and does not consume an application advisory-lock number. For an isolated installation, create its schema and pass the same name to every operation:search_path, and rejects names beyond PostgreSQL’s identifier limit.
MySQL uses GET_LOCK in a server-wide namespace. Its default is
headgate:migrate:<database>. Choose one stable namespace per installation if an
application or another Headgate installation could use that prefix:
Adopt an existing installation
The migrator refuses to apply version 1 over existingheadgate_* tables. Treating an
unknown, hand-installed schema as fresh could bless a partial installation.
1
Validate the existing schema
2
Adopt only a complete manifest
3
Validate the recorded installation
adopt writes history only when the complete current manifest passes. It does not repair
or infer missing DDL.
Online-safety ledger
Additive does not automatically mean online-safe. Table rewrites, blocking index builds,
and non-null columns without a safe backfill remain offline changes.
Library APIs
Rust exposesmigrate_postgres, migrate_mysql, validate_*, applied_*, adopt_*,
and the pure plan function. Go exposes the corresponding MigratePostgres,
MigrateMySQL, Validate*, Applied*, Adopt*, and Plan functions. Both languages
also provide explicit-schema PostgreSQL and named-lock MySQL variants.
Multiple installations
Keep migrations, stores, duties, schedules, workers, and wakeups inside one backend-native boundary.