Repository navigation
Flyway: single-pass CREATE INDEX CONCURRENTLY support (pin 13.4.0 + session-level lock + auto-repair) - #438
Merged
Merged
Conversation
…ession-level lock + auto-repair) Pin flyway/flyway to 13.4.0 everywhere, add -postgresql.transactional.lock=false to every migrate invocation (Flyway's default transactional advisory lock since 9.1.2 deadlocks against CIC), and run repair unconditionally before migrate in prod deploy to auto-clear a failed CIC migration's success=false history row. Documents the versioning trap for CIC data-fix migrations in AGENTS.md. Closes #407 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Ksbj9x1jrixy8qhSE5H46
Unconditional flyway repair (#438) silently realigns checksums of edited applied migrations instead of failing validation, so the no-edits invariant must now be enforced at PR time: fail on any edit/delete/rename of an existing migration file, diffed against the merge-base with the target branch, across all three bots' migrations dirs. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Ksbj9x1jrixy8qhSE5H46
Edits, deletes, and renames an existing migration in each bot's dir to verify migration-immutability.yml catches all three cases in real CI. This commit is reverted by the next one before merge. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Ksbj9x1jrixy8qhSE5H46
…erted)" This reverts commit ac3f052. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Ksbj9x1jrixy8qhSE5H46
A path-filtered required check never runs on PRs that don't touch migrations, blocking merge forever on a check that never reports. Run on every pull_request instead; the script exits 0 immediately when no migration files changed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Ksbj9x1jrixy8qhSE5H46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
Since Flyway 9.1.2 (commit 022a646),
migrateholds a transactional advisory lock across its own DB session (visible as a secondidle in transactionsession) for the duration of the run. That lock was added for PgBouncer transaction-pooling compatibility. It also means anyCREATE INDEX CONCURRENTLYmigration Flyway runs waits forever on Flyway's own lock — CIC can never commit inside the same transaction Flyway is holding.Our Azure Postgres is Burstable tier, where PgBouncer can't be enabled, so the transactional-lock behavior buys us nothing and only breaks CIC.
What changed
Pin
flyway/flywayto13.4.0everywhere (was unpinned:latest, which drifted 12.8.1→13.4.0 within 6 days):.github/workflows/_bot-deploy.yml,.github/workflows/alita-real-test.yml,.github/workflows/coupon-real-test.yml,src/coupon-hub-bot/docker-compose.dev.yml,src/alita-bot/docker-compose.dev.yml,tests/BotTestInfra/ContainerHelpers.fs.Add
-postgresql.transactional.lock=falseto everymigrateinvocation in those same places, switching Flyway's cross-run coordination lock to a session-level advisory lock (still serializes concurrent runs, releases on connection death — both proven in a container harness). Regular migration scripts are unaffected — they still run inside their own transaction and roll back atomically.Add an unconditional
flyway repairimmediately beforemigratein the prod deploy workflow (_bot-deploy.yml).repairis a proven no-op when nothing failed (checksum-safe), and is what clears thesuccess=falsehistory row a failed CIC migration leaves behind — without it, every later deploy is blocked forever. Not added to the dev composes / Testcontainers fixture (ContainerHelpers.fs) — doing so there would need real service-ordering restructuring, not a small change, and prod is the hard requirement.Document migration-authoring rules for CIC in
AGENTS.md(new subsection under "Database"): author CIC migrations idempotently in the normal versioned dir (no.sql.conf); if a CIC migrationVnfails on a data problem, the fix migration's version must sit strictly between the last-applied version andVn(e.g.V(n-1).1), never aboveVn— a higher version never runs beforeVn's identical retry, so it fails forever; unconditionalrepairmeans editing an already-applied migration silently realigns its checksum instead of failing validation.Add a new PR-time check (
migration-immutability.yml/scripts/check-migration-immutability.sh) that fails on any edit/delete/rename of an already-existing migration file (across all three bots' migrations dirs) — unconditionalflyway repairsilently realigns checksums of edited applied migrations instead of failing validation, so the no-edits invariant now has to be enforced at PR time.Test plan
dotnet build— green, 0 warnings/errorsdotnet test tests/MultiPodTests -c Release— 15/15 passed (1m40s); this suite's fixture (BotContainerBase/MultiPodContainerBase) exercisesContainerHelpers.fs'screateFlywayContainer, so it proves the pinned13.4.0image +-postgresql.transactional.lock=falseflag work end-to-end locally (podman-backed Testcontainers)actionlinton the three touched workflow files — cleanscripts/check-migration-immutability.shagainst a scratch worktree (not this branch): edit-existing → detected (M), delete-existing → detected (D), rename-existing → detected (R), add-then-edit-in-same-PR → passesactionlinton the new workflow file — cleanCloses #407
🤖 Generated with Claude Code
https://claude.ai/code/session_011Ksbj9x1jrixy8qhSE5H46