You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3fe9169
Browse filesBrowse the repository at this point in the historyBrowse files
chore(db): check that migrations bound their lock wait and stay append-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>
Copy file name to clipboardExpand all lines: docs/database.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -287,7 +287,7 @@ apply:
287
287
288
288
| Location | What goes there |
289
289
|---|---|
290
-
|`migrations/NNNN_<name>.sql`| The forward migration for existing databases. Use the next free number; rebase and renumber on a collision. Never edit a merged migration: its checksum changes, and relays that run the migrator fail with sqlx `VersionMismatch`. Fix forward in a new migration. |
290
+
|`migrations/NNNN_<name>.sql`| The forward migration for existing databases, numbered after the newest on main. Merged migrations are append-only, because relays that already ran one fail with sqlx `VersionMismatch` when its checksum changes. `migration_versions_are_unique`and `just migrations-append-only-check` enforce both. A deliberate rewrite that every deployment has agreed to takes the `migration-edit` PR label. |
291
291
|`schema/tables/public/<table>.sql`| The table's final `CREATE TABLE` and its `CREATE INDEX` statements, one table per file. This is the declarative schema source. |
292
292
|`schema/schema.sql`| An `\i` line for each new file, after the tables it depends on. |
293
293
|`schema/types/`, `schema/sequences/`, `schema/partitions/`, `schema/seeds/`| The matching non-table objects. The layout test permits nothing else here. `schema/` has no `functions/` or `triggers/` directory, and Rule 1 forbids adding one. |
@@ -446,8 +446,9 @@ foreign keys on `events` and `delivery_log`, apply `0104`.
446
446
447
447
### 6. Bound every lock and statement
448
448
449
-
- Every migration MUST start with `SET LOCAL lock_timeout`, and SHOULD set
450
-
`SET LOCAL statement_timeout` when a statement can scan. A migration that
449
+
- Every migration MUST start with `SET LOCAL lock_timeout` (a buzz-db test
450
+
enforces it after `0066`), and SHOULD set `SET LOCAL statement_timeout`
451
+
when a statement can scan. A migration that
451
452
cannot get its lock fails and is retried. It MUST NOT queue behind
452
453
traffic on a hot table.
453
454
- With `BUZZ_AUTO_MIGRATE` on, migrations are the whole upgrade procedure, so
0 commit comments