Draft: feat(migrations): run database migrations with Theseus Migrator instead of goose
What does this MR do?
Moves Artifact Registry's database migrations from goose, embedded in the binary and applied by every pod at boot, to Theseus Migrator, run as a Helm hook from a derived image before each release rolls out. This is the end state of gitlab-org/ops&26 in one tree, opened as a draft so the team can react to real diffs on the open design choices before it is split along the epic's issues.
Draft. Not for merging as one MR. The plan-MR-first rule still applies to the real switch; this branch is the reference the plan is written from.
Design choices to react to
| Choice | Taken here | Alternative |
|---|---|---|
| Where the files live | db/migrations/ + db/Dockerfile, Migrator's contract layout and the defaults of the common-ci-tasks migrator component |
keep internal/datastore/migrations/sql/ and set the component's migrations_dir input |
| The three comment-only Downs | SELECT 1; so they stay reversible and the round trip needs no --skip-irreversible |
leave them empty, which Migrator reads as irreversible |
-- migrator:no-transaction placement |
on both the forward and the down file wherever the goose file had NO TRANSACTION, because goose applied it file-wide; 4 files declared it on one side only and now carry it on both |
per side, after a hand review of those 4 |
| Existing installs | BASELINE_VERSION=20261006115943 in .runway/values.yaml for GitLab.com and staging; remove after the first successful deploy |
goose-history import (ask 2 on migrator#3), not built |
| River's start gate | polls for the five River tables present at head (river_job, river_leader, river_migration, river_notification, river_queue); a test pins the set against the vendored River chain |
to_regclass('river_job') alone, which opens mid-chain because river_main_007 drops two tables River created earlier |
| CLI in CI | scripts/ci/install-migrator.sh pinned by GL_MIGRATOR_VERSION |
.install_migrator from common-ci-tasks once !1935 releases |
What changes
Migrations. 121 goose files converted mechanically into db/migrations/<v>_<name>.sql and db/migrations/down/<v>_<name>.down.sql, formatted with pgFormatter. Content is otherwise byte for byte. db/embed.go embeds the set for the test harness's template hash and the schema suites' file reads.
Service. The boot-time runner (internal/datastore/migrations/runner.go, cmd/artifact-registry/migration_runner.go) and the migrations readiness key are gone. The app becomes ready against an empty database; River waits for its tables. goose leaves go.mod.
Tests. internal/datastore/migrations now wraps the CLI (Apply, Rollback, ReadStatus, HasPending, Checksum, HeadVersion). testutil.WithMigration(migrations.Apply, migrations.Checksum) replaces the goose pair at 53 call sites. A new integration test boots the assembled app against an empty database, asserts readiness is 200 with River not started, applies the schema, and asserts River comes up.
CI. The common-ci-tasks migrator@v5.34 component (validate_migrations, build_migrations; its round trip disabled because db:migrate already runs up, down --to-version 0, up on PG 16/17/18). Every job with a Postgres service installs the CLI. squawk, pgFormatter, immutability, ordering, and the River freshness check run over both globs.
Chart and deploy. Migrator's contrib/fairway/migrate-job.yaml committed verbatim under chart/templates/custom/, re-included in .gitignore, copied into the e2e rig's generated chart by scripts/chart-gen.sh. .runway/fairway.yaml names the migrations image; .runway/values.yaml points Runway at the security mirror's copy and carries the baseline. The e2e rig builds <repo>-migrations:<tag> beside the app image and imports both.
Local dev and docs. scripts/db/migrator.sh (binary, PATH, or the Docker image), mise run db:* through it, migrator new for scaffolding. docs/dev/database-migrations.md rewritten; database.md, go-testing.md, go-libraries.md, the run recipe and the db-review-prep skill updated.
Verification
Run locally against Postgres 18 with the migrator built from the v1.9.0 commit (the colima VM could not pull images). CI's three-version matrix is the first full run.
| Check | Result |
|---|---|
migrator validate on the converted set |
0 violations |
Converted set, up / down --to-version 0 / up, schema diffed against a goose-built database |
identical (74,162-line dump) |
internal/datastore/migrations core suite (TestMigrations_*) |
4/4 pass; up/down/up 585s, five concurrent Apply 19s |
internal/datastore/migrations full suite |
240 pass / 2 fail on a stock container (out of shared memory, SQLSTATE 53200, on the namespace cascade; CI's max_locks_per_transaction=1024 is what the suite assumes); rerun with CI's options reached 110 pass / 0 fail before the local cutoff |
cmd/artifact-registry unit suite |
pass (three TestWireStorage_CloudCDN* need GCP credentials, unrelated) |
cmd/artifact-registry integration: lifecycle, the new first-install test, OCI wire suite |
pass (first install: readiness 200 on an empty schema, River starts after Apply) |
internal/testutil integration suite |
pass |
go test ./... (untagged) |
pass; internal/virtual fails only under whole-tree parallel load and passes alone, untouched here |
go vet with and without integration |
clean |
| golangci-lint 2.13.2 (CI pin) over every touched package | 0 issues across the 19 touched packages |
scripts/ci/check-comment-caps.sh --base origin/main |
0 |
squawk 2.66.0 over db/migrations/** |
0 issues in 226 files (one require-statement-timeout the single-file layout had masked, now suppressed inline with its reason) |
scripts/ci/install-migrator.sh |
cold install, cache hit, and corrupted-slot reinstall on golang:1.26-alpine (busybox wget); real asset download and checksum on the host |
Hook render: fairway generate + helm template with .runway/values.yaml |
hook annotation, security-mirror image, pull secret, three mounts, BASELINE_VERSION env |
| River extractor against the converted files | up to date, no drift |
| shellcheck, shfmt, yamllint, markdownlint (CI invocation) | clean |
Not run: the e2e caproni rig, vale, lychee.
Known gaps and follow-ups
- Pre-switch branches. After adoption with
BASELINE_VERSION=head, a migration whose version sorts below the baseline is silently treated as baselined and never applied; with a later executed revision present it instead fails as "has changed" because Atlas chains per-file hashes. Every open migration MR must re-timestamp at the switch. Both behaviours are being raised on the Migrator side. - Self-Managed installs behind head still need goose-history import or a required stop (migrator#3 ask 2).
- Registry sync.
build_migrationspushes to the project's own registry; the release-platform sync from the security mirror to canonical covers the app image and chart today and needs the migrations image added before Self-Managed installs can pull it. - Deployment ordering. The Runway trigger does not yet
needbuild_migrations; a deploy that races the image build sees the hook's pod wait on the pull until it lands. - !3223 (merged) edits
docs/dev/database-migrations.mdonmain; this branch rewrites it and will conflict. - Diff size: 121 files × 2 plus their deletions is the conversion; the Go, CI, and docs portions are listed above. Splitting is the follow-up this draft exists to inform.
No e2e scenario row is added or changed: migrations are not observable from outside the service, and the first-install contract is covered by the new composition-root integration test. No docs/user/ change: no customer-callable surface moves.
Impact
- Who: operators of every Artifact Registry install (GitLab.com, staging, Self-Managed, the e2e rig); anyone running the service or its integration tests locally.
- Action required: installs must publish and pull the
migrationsimage alongside the app image, and the first Runway deploy carriesbaselineVersion, removed afterwards. Local runs need the migrator CLI (go install gitlab.com/gitlab-org/theseus/migrator/cmd/migrator@v1.9.0plusbrew install ariga/tap/atlas) or letscripts/db/migrator.shfall back to Docker. - What changes without action: the binary no longer migrates at boot;
/-/readinessloses itsmigrationskey; a failed migration stops the Helm upgrade instead of crash-looping the fleet; on a first install requests fail until the post-install Job finishes. - Compatibility: breaking for any deploy path that does not run the chart hook (none known besides local dev, which the scripts cover).
Related to #1569