ci(migrations): add immutability guard against sqlx checksum drift #62

Merged
Claude-Run merged 1 commit from feat/LINKS-26-migration-immutability-guard into main 2026-06-30 21:45:55 +02:00
Member

sqlx records a SHA-384 checksum of each migration in _sqlx_migrations on apply and re-verifies it on every startup, so editing an already-applied migration makes every database that ran it refuse to boot ("migration N was previously applied but has been modified"). This is what broke the mokosh-server v0.4.0 deploy on nc-01 (DEV-395); nothing in this repo caught the edit.

Add scripts/check-migration-immutability.nu, which diffs origin/main...HEAD with --diff-filter=MRD over migrations/ and fails (exit 1) listing any committed migration that was modified, renamed, or deleted, telling the author to add a new migration instead. Adding a new file passes. It exits 2 (fail loud) when the diff itself cannot run, so a broken base never reads as "nothing changed".

Wire it into .forgejo/workflows/check.yml as a step and set fetch-depth: 0 on the checkout so the merge-base with origin/main is available. Document the immutability rule and the guard in docs/DATABASE.md.

#LINKS-26

sqlx records a SHA-384 checksum of each migration in _sqlx_migrations on apply and re-verifies it on every startup, so editing an already-applied migration makes every database that ran it refuse to boot ("migration N was previously applied but has been modified"). This is what broke the mokosh-server v0.4.0 deploy on nc-01 (DEV-395); nothing in this repo caught the edit. Add scripts/check-migration-immutability.nu, which diffs origin/main...HEAD with --diff-filter=MRD over migrations/ and fails (exit 1) listing any committed migration that was modified, renamed, or deleted, telling the author to add a new migration instead. Adding a new file passes. It exits 2 (fail loud) when the diff itself cannot run, so a broken base never reads as "nothing changed". Wire it into .forgejo/workflows/check.yml as a step and set fetch-depth: 0 on the checkout so the merge-base with origin/main is available. Document the immutability rule and the guard in docs/DATABASE.md. #LINKS-26
ci(migrations): add immutability guard against sqlx checksum drift
All checks were successful
Check / clippy + fmt + tests (pull_request) Successful in 21s
Create release / Create release from merged PR (pull_request) Has been skipped
33918519eb
sqlx records a SHA-384 checksum of each migration in _sqlx_migrations on apply and re-verifies it on every startup, so editing an already-applied migration makes every database that ran it refuse to boot ("migration N was previously applied but has been modified"). This is what broke the mokosh-server v0.4.0 deploy on nc-01 (DEV-395); nothing in this repo caught the edit.

Add scripts/check-migration-immutability.nu, which diffs origin/main...HEAD with --diff-filter=MRD over migrations/ and fails (exit 1) listing any committed migration that was modified, renamed, or deleted, telling the author to add a new migration instead. Adding a new file passes. It exits 2 (fail loud) when the diff itself cannot run, so a broken base never reads as "nothing changed".

Wire it into .forgejo/workflows/check.yml as a step and set fetch-depth: 0 on the checkout so the merge-base with origin/main is available. Document the immutability rule and the guard in docs/DATABASE.md.

#LINKS-26
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
a8n-tools/rusty-links!62
No description provided.