Version v0.5.7 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.
Add a migration
The rules are in migrations/AGENTS.md.
Pick the number. Take the highest number in
migrations/on the latestmainand add one. Check open PRs that add a migration too; whoever merges second renumbers.Write both files with the same name:
NNN_short_name.up.sqlandNNN_short_name.down.sql. Start each with a comment saying what it changes and why, and the issue or ADR.Write every migration as expand/contract (ADR 0090). A release only adds (the expand phase): new tables, new indexes, and columns that are nullable or carry a constant default. The previous release’s binary must continue to run on the newer schema so that
helm rollbackis always safe. Removals, renames, and NOT NULL columns without defaults happen in a contract phase at least one minor release later, once no supported release binary expects the old shape. When targeting a patch, keep it additive and within the safety bar of ADR 0068.Regenerate and test:
make sqlc # queries, when the schema they read changed go test ./migrations/ # numbering, pairs, index and role rules make test-integration # the storage layer against a real PostgresProve upgrade and rollback on a database with data from the previous release:
make migrate-up, check the server, thenmake migrate-downonce per new migration and check again. Put the timings in the PR; the release candidate review needs them (AGENTS.md, review 7).Document it. A migration is user-facing: add a section to upgrades when it takes noticeable time or needs an action, and a changelog fragment. Every migration also gets its row in the recovery table of an interrupted migration: the version left dirty, what to do before
force, and the version to force (the one whose schema the database holds once the file was cut short).Before merging, merge the latest
maininto your branch; if the number is taken, rename both files to the next free number and rerun step 4.