Repository navigation
chore(db): check that migrations bound their lock wait and stay append-only - #10082
salman1993 wants to merge 1 commit into
Conversation
3fe9169 to
19fdb70
Compare
…d-only A new buzz-db test fails when a relay migration after 0066, or a push gateway migration after 0006, does not start with SET LOCAL lock_timeout. scripts/check-migrations-append-only.sh fails when a .sql file that is already on main is edited, renamed or deleted in either migrations directory. It runs in CI on pull requests, in the pre-push hook and in `just check`. BUZZ_ALLOW_MIGRATION_EDITS=1 or the migration-edit PR label lets a deliberate rewrite through. The prose these checks replace is shortened in docs/database.md and the migrations AGENTS.md files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Salman Mohammed <smohammed@squareup.com>
19fdb70 to
97b31b5
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🔐 Codex Security Review
Review SummaryOverall Risk: NONE
FindingsNo concrete security, correctness, or reliability findings were identified. Notes
Generated by Codex Security Review | |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97b31b5768
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| changed="$(git diff --no-renames --name-status "$base" HEAD -- \ | ||
| 'migrations/*.sql' 'crates/buzz-push-gateway/migrations/*.sql' | grep -v '^A' || true)" |
There was a problem hiding this comment.
Propagate failures from the migration diff
When CHECK_MIGRATIONS_BASE names an unavailable revision, the || true suppresses the failure of the entire pipeline, not just grep's no-match status. Reproducing with CHECK_MIGRATIONS_BASE=refs/heads/nonexistent-review-base bash scripts/check-migrations-append-only.sh prints fatal: bad revision but exits 0. This makes the append-only gate report success without checking any migrations. Capture the Git output separately and propagate its failure before filtering added files.
AGENTS.md reference: AGENTS.md:L232-L236
Useful? React with 👍 / 👎.
Summary
This adds two checks for migration rules that are written in
docs/database.mdbut that nothing enforced. As in #10077, which added the clippy bans, the goal is to turn rules that review catches into checks whose errors name the fix, then remove the prose they replace.Every new migration bounds its lock wait
new_migrations_start_by_bounding_the_lock_wait(buzz-db, next to the other migration source tests) fails when a migration's first statement isn'tSET LOCAL lock_timeout. A DDL statement queued behind a long transaction blocks every query on the table until it gets the lock. Without a timeout, one migration can stall the relay fleet during a deploy. docs/database.md rule 6 already requires the timeout, and review caught a migration without it in #8496.0066all comply today (45 of 45). Older ones predate the rule and are exempt.0001–0006predate the rule and are exempt.0007–0009comply.deadlock_timeoutdoesn't pass.Merged migrations are append-only
scripts/check-migrations-append-only.shfails when a.sqlfile that is already on main is modified, renamed or deleted, inmigrations/orcrates/buzz-push-gateway/migrations/. sqlx stores each applied migration's checksum, so an edited migration makes every database that already ran it fail withVersionMismatchat startup. Adding files and editingAGENTS.mdare still allowed.It diffs from the merge base with origin/main, or from
HEAD^1(the PR base) in GitHub Actions, the same way the file-size check does. It runs:git diff, so it isn't path-filtered);just check.Escape hatch for a deliberate rewrite that every deployment has agreed to: the
migration-editPR label, orBUZZ_ALLOW_MIGRATION_EDITS=1locally. CI reads the PR's labels when the step runs, so a re-run picks up a label added after the push. The label doesn't exist yet, so a maintainer needs to create it.Docs
The prose these checks replace is cut from
migrations/AGENTS.mdand the gateway'smigrations/AGENTS.md.docs/database.mdkeeps the reason for each rule and names the check that enforces it.Test plan
cargo nextest run -p buzz-db --lib -E 'test(new_migrations_start_by_bounding_the_lock_wait)'passes. It fails and lists both files when I addmigrations/0999_planted.sql(timeout only in a comment, afterstatement_timeout) and a gateway0099_planted.sqlwith onlydeadlock_timeout.just migrations-append-only-checkpasses on this branch. On throwaway commits it fails for an edited0110, a renamed0001and a deleted gateway0009. It passes for a new migration plus anAGENTS.mdedit, and withBUZZ_ALLOW_MIGRATION_EDITS=1. It also fails inGITHUB_ACTIONS=true(HEAD^1) mode.actionlinton ci.yml reports only the existing unknown-runner-label warnings.cargo fmt --all --checkandcargo clippy -p buzz-db --all-targets -- -D warningspass.gh pr viewlabel lookup. This PR's CI covers it.🤖 Generated with Claude Code