Skip to content

ci: guard against editing applied migrations and version reuse#574

Merged
ExtraToast merged 1 commit into
mainfrom
ci/migration-guard
Jun 4, 2026
Merged

ci: guard against editing applied migrations and version reuse#574
ExtraToast merged 1 commit into
mainfrom
ci/migration-guard

Conversation

@ExtraToast

Copy link
Copy Markdown
Owner

Why

An agent PR reworded the leading comment of an already-applied Flyway migration (assistant-api V12). Flyway checksums the entire file, so the reword flipped the checksum and validate hard-failed on boot — assistant-api and assistant-api-ws crashlooped in production. Nothing in CI flagged it before merge. (The repair is #573.)

What

infra/scripts/check-migrations.sh, run by a new Migration Guard workflow on every PR, enforces two invariants:

  • Immutability — a migration that already exists on the base branch may not be modified, renamed, or deleted. Add a new migration with a higher version instead. A reviewed, deliberate correction can carry the allow-migration-change label to downgrade this to a warning (used for the V12 restore in assistant-api: restore V12 migration to its applied content (fix Flyway checksum crashloop) #573).
  • Versioning — within each service, migration versions are unique and every newly added migration's version is strictly greater than the highest version already on the base branch (no reuse, no backfilling a lower version).

knowledge-api splits versions across db/migration/ and db/migration-pg/; both trees share one per-service version namespace, which the script accounts for.

The workflow runs unconditionally (a PR touching no migrations still reports a green check in seconds), so it is safe to mark as a required status check — recommended, since that is what turns this from advisory into a real gate.

Verified

Locally: passes on a clean tree, fails with a clear message on a committed edit to an existing migration (the exact V12 failure mode), and the allow-migration-change override downgrades that to a warning.

An agent PR reworded the comment in an already-applied Flyway migration
(assistant-api V12). Flyway checksums the whole file, so the edit flipped the
checksum and crashlooped assistant-api on the next boot. Nothing in CI caught
it before merge.

check-migrations.sh enforces two invariants on every PR:
  - immutability: a migration present on the base branch may not be modified,
    renamed, or deleted (label allow-migration-change downgrades this to a
    warning for a reviewed correction);
  - versioning: per service, versions are unique and each newly added
    migration's version exceeds the highest already on the base branch.

knowledge-api splits versions across migration/ and migration-pg/; both trees
share one per-service version namespace, which the script accounts for. The
workflow runs unconditionally so it is safe to require as a status check.
@ExtraToast ExtraToast added the enhancement New feature or request label Jun 4, 2026
@ExtraToast ExtraToast self-assigned this Jun 4, 2026
@ExtraToast ExtraToast merged commit 439628b into main Jun 4, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant