ci: add migration-immutability guard for sqlx checksum drift #301
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/BUNYIP-293-migration-immutability-guard"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
sqlx checksums every applied migration in _sqlx_migrations and re-verifies it on every startup, so modifying, renaming, or deleting a migration already applied to a database makes that database refuse to boot ("migration was previously applied but has been modified"). This took down the mokosh-server v0.4.0 deploy on nc-01 (DEV-395) and has bitten this repo before (BUNYIP-79 edited 11 applied migrations in place; see scripts/reconcile-sqlx-checksums.md). Nothing in CI caught the edit.
Add scripts/check-migration-immutability.sh (sibling to the version-number gate): it diffs bunyip-api/migrations against the merge-base with origin/main with --diff-filter=MRD and fails (exit 1, naming the offending files and telling the author to add a new migration) if any committed migration was modified, renamed, or deleted. Adding new migration files passes. It fails loud (exit 2) if the diff itself cannot run, so a missing base ref or shallow clone never silently 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 migration immutability in CLAUDE.md.
#BUNYIP-293
sqlx checksums every applied migration in _sqlx_migrations and re-verifies it on every startup, so modifying, renaming, or deleting a migration already applied to a database makes that database refuse to boot ("migration <version> was previously applied but has been modified"). This took down the mokosh-server v0.4.0 deploy on nc-01 (DEV-395) and has bitten this repo before (BUNYIP-79 edited 11 applied migrations in place; see scripts/reconcile-sqlx-checksums.md). Nothing in CI caught the edit. Add scripts/check-migration-immutability.sh (sibling to the version-number gate): it diffs bunyip-api/migrations against the merge-base with origin/main with --diff-filter=MRD and fails (exit 1, naming the offending files and telling the author to add a new migration) if any committed migration was modified, renamed, or deleted. Adding new migration files passes. It fails loud (exit 2) if the diff itself cannot run, so a missing base ref or shallow clone never silently 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 migration immutability in CLAUDE.md. #BUNYIP-293763afdfb7dee6b204769