fix(migrations): auto-reconcile BUNYIP-79 in-place-edited checksums at startup #173
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bunyip-79-migration-checksum-reconcile"
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?
Closes #172.
Problem
Commit
9c082eb(BUNYIP-79) edited 11 already-applied migration files in place. sqlx records a per-file SHA-384 in_sqlx_migrationsand recomputes it on every start, so any database that applied the original bodies fails startup withmigration <version> was previously applied but has been modifiedand crash-loops. A developer OP was down ~24h on exactly this; with the API dead, Traefik had no backend and dependent relying parties (a lets-chat dev stack) could not complete OIDC discovery.Fix
New
bunyip-api/src/migrate_reconcile.rs, run once at startup before the migrator. For each of the 11 affected versions, if the recorded checksum still equals the pre-edit value, it is rewritten to the current embedded checksum. The UPDATE is guarded byAND checksum = <pre-edit hash>:9c082eb(recorded == current) are untouched (rows_affected == 0).The replacement value is read from the embedded migrator, not hardcoded, so it stays correct if a listed file is touched again.
Verification
legacy_allowlist_matches_embedded_migratorunit test: every listed version exists in the embedded set, each hash is a well-formed SHA-384, and the pre-edit hash differs from the current embedded hash (proving the file really was edited). Runs underjust test(--lib), no database required.BUNYIP-79 reconcile: rewrote stale migration checksumfor both,reconciled 2 ... count=2, thenDatabase migrations completed successfullyand the API listening, instead of crash-looping. The two rows are left at the current file hashes (idempotent thereafter).cargo fmt,cargo clippy --lib -p bunyip-api, andscripts/check-migration-versions.share clean.Scope / follow-up
Reconciliation only unblocks startup. A row marked applied is never re-run, so the DDL guards
9c082ebadded are NOT retro-applied to a database that already ran the original bodies. Delivering those guards to already-migrated data requires forward-only migrations and is intentionally left as a follow-up; the README and module docs state this and reinforce that future behavioral changes must ship as fresh migrations, not in-place edits.