Repository navigation
chore(db): check that migrations bound their lock wait and stay append-only #10082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/usr/bin/env bash | ||
| # Fails when a migration that is already on main is edited, renamed or deleted. | ||
| # | ||
| # sqlx stores each applied migration's checksum. An edited migration makes | ||
| # every database that already ran it refuse to start (VersionMismatch), and a | ||
| # deleted or renamed one leaves those databases out of step with new ones. | ||
| # Fix forward with a new migration instead. | ||
| # | ||
| # The base is the merge base with origin/main, or the PR base (HEAD^1 of the | ||
| # merge commit) in GitHub Actions. CHECK_MIGRATIONS_BASE overrides it. | ||
| # | ||
| # Escape hatch for a deliberate rewrite, such as a consolidation every | ||
| # deployment has agreed to: BUZZ_ALLOW_MIGRATION_EDITS=1 locally, or the | ||
| # `migration-edit` label on the PR in CI. | ||
| set -euo pipefail | ||
|
|
||
| cd "$(git rev-parse --show-toplevel)" | ||
|
|
||
| if [[ "${BUZZ_ALLOW_MIGRATION_EDITS:-}" == "1" ]]; then | ||
| echo "Migration edits allowed by BUZZ_ALLOW_MIGRATION_EDITS=1." | ||
| exit 0 | ||
| fi | ||
|
|
||
| base="${CHECK_MIGRATIONS_BASE:-}" | ||
| if [[ -z "$base" ]]; then | ||
| if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then | ||
| base="HEAD^1" | ||
| elif ! base="$(git merge-base origin/main HEAD)"; then | ||
| echo "Could not find the merge base with origin/main. Fetch origin/main or set CHECK_MIGRATIONS_BASE." >&2 | ||
| exit 2 | ||
| fi | ||
| fi | ||
|
|
||
| changed="$(git diff --no-renames --name-status "$base" HEAD -- \ | ||
| 'migrations/*.sql' 'crates/buzz-push-gateway/migrations/*.sql' | grep -v '^A' || true)" | ||
|
|
||
| if [[ -n "$changed" ]]; then | ||
| echo "These migrations are already on main and must not change:" >&2 | ||
| echo "$changed" >&2 | ||
| echo "Revert them and add a new migration that fixes forward. See docs/database.md." >&2 | ||
| exit 1 | ||
| fi | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
CHECK_MIGRATIONS_BASEnames an unavailable revision, the|| truesuppresses the failure of the entire pipeline, not just grep's no-match status. Reproducing withCHECK_MIGRATIONS_BASE=refs/heads/nonexistent-review-base bash scripts/check-migrations-append-only.shprintsfatal: bad revisionbut 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 👍 / 👎.