Skip to content

chore(db): check that migrations bound their lock wait and stay append-only - #10082

Closed
salman1993 wants to merge 1 commit into
mainfrom
smohammed/migration-checks
Closed

salman1993 wants to merge 1 commit into
mainfrom
smohammed/migration-checks

Conversation

@salman1993

@salman1993 salman1993 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds two checks for migration rules that are written in docs/database.md but 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't SET 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.

  • Relay migrations after 0066 all comply today (45 of 45). Older ones predate the rule and are exempt.
  • The push gateway's migrations are covered too, because database.md says every rule applies to both. Gateway 0001–0006 predate the rule and are exempt. 0007–0009 comply.
  • The test reads the first statement with comments stripped, so a commented-out timeout or a deadlock_timeout doesn't pass.

Merged migrations are append-only

scripts/check-migrations-append-only.sh fails when a .sql file that is already on main is modified, renamed or deleted, in migrations/ or crates/buzz-push-gateway/migrations/. sqlx stores each applied migration's checksum, so an edited migration makes every database that already ran it fail with VersionMismatch at startup. Adding files and editing AGENTS.md are 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:

  • in CI on pull requests, next to "File size policy" in the path-detection job;
  • in the pre-push hook (one git diff, so it isn't path-filtered);
  • in just check.

Escape hatch for a deliberate rewrite that every deployment has agreed to: the migration-edit PR label, or BUZZ_ALLOW_MIGRATION_EDITS=1 locally. 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.md and the gateway's migrations/AGENTS.md. docs/database.md keeps 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 add migrations/0999_planted.sql (timeout only in a comment, after statement_timeout) and a gateway 0099_planted.sql with only deadlock_timeout.
  • just migrations-append-only-check passes on this branch. On throwaway commits it fails for an edited 0110, a renamed 0001 and a deleted gateway 0009. It passes for a new migration plus an AGENTS.md edit, and with BUZZ_ALLOW_MIGRATION_EDITS=1. It also fails in GITHUB_ACTIONS=true (HEAD^1) mode.
  • actionlint on ci.yml reports only the existing unknown-runner-label warnings.
  • cargo fmt --all --check and cargo clippy -p buzz-db --all-targets -- -D warnings pass.
  • Not run locally: the CI step itself, including the gh pr view label lookup. This PR's CI covers it.

🤖 Generated with Claude Code

@salman1993
salman1993 force-pushed the smohammed/migration-checks branch from 3fe9169 to 19fdb70 Compare December 1, 2026 21:17
Base automatically changed from smohammed/clippy-ban-list to main December 2, 2026 01:21
…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>
@salman1993
salman1993 force-pushed the smohammed/migration-checks branch from 19fdb70 to 97b31b5 Compare December 2, 2026 01:33
@salman1993
salman1993 marked this pull request as ready for review December 2, 2026 01:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T01:36:38.628921Z 97b31b5 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@salman1993
salman1993 deployed to codex-review December 2, 2026 01:34 — with GitHub Actions Active
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: ce01ea25b35c6ee85b87cc533b2deb6b052f0bcb...97b31b57682b04b64b371e182f0670bae2504746
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete security, correctness, or reliability regressions found in the authorized PR range.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • Review used read-only source and history inspection. Builds, tests, and repository scripts were not executed.

Generated by Codex Security Review |
Requested by: @salman1993 |
Workflow run

@salman1993 salman1993 closed this Dec 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +34 to +35
changed="$(git diff --no-renames --name-status "$base" HEAD -- \
'migrations/*.sql' 'crates/buzz-push-gateway/migrations/*.sql' | grep -v '^A' || true)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

This branch was successfully deployed

1 active deployment
codex-review — 97b31b57 Deployed Dec 2, 2026 by salman1993 via Run Codex Security Review #19134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant