Skip to content

Commit 7e94503

Browse files
Stop using the unused delivery_log and subscriptions tables (#9746)
## Summary `delivery_log` and `subscriptions` came with the initial schema for a delivery feature that was never built. No code has ever written to them. This PR removes every reader, writer, partition-manager entry and deletion selection, so a follow-up contract migration can drop both tables (`docs/database.md` Rule 5: drop only after the release that stops using a table is fully deployed). - **Partition manager:** manages `events` only. It no longer creates or audits `delivery_log` partitions. - **User deletion:** the content, account and profile handlers no longer select, delete or recheck rows in either table. - **Community deletion:** both tables move from `EXPECTED_SCOPED_TABLES`/`PURGE_SCOPED_TABLES` to a new `RETIRING_SCOPED_TABLES` list. The catalog accepts each one present or absent. The purge deletes its rows only while it exists. `validate_approved_schema` accepts a frozen retiring table that has since been dropped, and no other missing table. Without this, every community deletion would fail its exact catalog check once the tables are gone. - **Docs:** a short "Retiring a tenant-owned table" section in `docs/database.md`, plus partition-monitoring and cleanup docs. The tables, their schema files, `.pgschemaignore` entries and the partition primary-key lint exception stay until the drop migration. ### Rollout 1. Deploy this release to every relay, deletion executor and operator CLI. Older binaries fail community deletion's exact catalog check after the drop. 2. Then ship the drop migration and remove the schema entries. Operators with external tooling that expects `delivery_log` to exist must update it first. The partition audit stops emitting `buzz_partition_audit_*` series with `table="delivery_log"`. Alerts keyed on that label will go quiet. ### What got simpler Two tables' worth of code paths are gone: partition management, the audit, and five deletion handlers stop special-casing them. The follow-up removes the tables and the `RETIRING_SCOPED_TABLES` entries. ### Testing On a remote workstation at `3675ff17`: `cargo fmt --check`, `clippy -D warnings` for buzz-db, buzz-deletion and buzz-relay (all targets), unit tests for buzz-db (lib and tests), buzz-deletion and buzz-relay bins, and `scripts/postgres-test-run.sh` for buzz-db partition/deletion/migration tests (294 passed) and all buzz-deletion Postgres tests (44 passed). The new tests cover: retiring tables purged and verified while present; a request inventoried before a real `DROP TABLE` still purges and verifies; `validate_approved_schema` tolerates only retiring tables vanishing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Luke Tornquist <tornquist@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8827f98 commit 7e94503

30 files changed

Lines changed: 798 additions & 641 deletions

‎.pgschemaignore‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# pgschema reads this file from its working directory; every caller runs it
22
# from the repository root.
33
#
4-
# The relay's partition manager creates dated `events` / `delivery_log`
5-
# monthlies at runtime (see crates/buzz-db/src/store/partition/). They are not
6-
# declared in schema/partitions/, so without this file re-applying pgschema to a
7-
# database a relay has used drops them, and their rows, with
8-
# `DROP TABLE IF EXISTS ... CASCADE`. Only the monthlies schema/partitions/
4+
# The relay's partition manager creates dated `events` monthlies at runtime
5+
# (see crates/buzz-db/src/store/partition/). Older relays also created
6+
# `delivery_log` monthlies; their pattern stays until a migration drops that
7+
# table. These monthlies are not declared in schema/partitions/, so without
8+
# this file re-applying pgschema to a database a relay has used drops them, and
9+
# their rows, with `DROP TABLE IF EXISTS ... CASCADE`. Only the monthlies schema/partitions/
910
# declares stay managed by pgschema; keep the `!` exemptions below in sync with
1011
# them.
1112
[tables]

‎ARCHITECTURE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ All database access. Uses `sqlx::query()` (runtime, not compile-time macros) —
467467
| `channel.rs` | Channel CRUD, membership management, role enforcement (transactional) |
468468
| `feed.rs` | `query_mentions` (INNER JOIN event_mentions), `query_needs_action`, `query_activity` |
469469
| `workflow.rs` | Full workflow/run/approval CRUD; SHA-256 hashed approval tokens |
470-
| `partition.rs` | Monthly range partitioning for `events` and `delivery_log` tables: read-only catalog audit plus advisory-locked, time-bounded maintenance that creates uncovered months and advances an empty catch-all (`partition/maintenance.rs`) |
470+
| `partition.rs` | Monthly range partitioning for the `events` table: read-only catalog audit plus advisory-locked, time-bounded maintenance that creates uncovered months and advances an empty catch-all (`partition/maintenance.rs`) |
471471
| `dm.rs` | DM channel management |
472472
| `reaction.rs` | Reaction storage and retrieval |
473473
| `thread.rs` | Thread/reply tracking |

‎crates/buzz-db/src/runtime/migration.rs‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,7 @@ mod postgres_tests {
15521552
];
15531553
for table in crate::deletion::EXPECTED_SCOPED_TABLES
15541554
.iter()
1555+
.chain(crate::deletion::RETIRING_SCOPED_TABLES)
15551556
.filter(|table| !never_fenced.contains(table))
15561557
{
15571558
assert!(
@@ -3424,8 +3425,9 @@ mod postgres_tests {
34243425
"reconcile did not attach both catch-alls: {declared_bounds:?}"
34253426
);
34263427

3427-
// The relay's default startup pass advances each catch-all into dated
3428-
// monthlies schema/partitions/ does not declare.
3428+
// The relay's default startup pass advances the `events` catch-all into
3429+
// dated monthlies schema/partitions/ does not declare. `delivery_log` is
3430+
// retired from partition management, so its catch-all stays as declared.
34293431
maintain_partitions(
34303432
&pool,
34313433
PARTITION_MANAGER_MONTHS_AHEAD,
@@ -3442,13 +3444,17 @@ mod postgres_tests {
34423444
"maintenance dropped or detached a catch-all: {advanced_bounds:?}"
34433445
);
34443446
for (declared, advanced) in declared_bounds.iter().zip(&advanced_bounds) {
3445-
assert_ne!(declared, advanced, "catch-all did not advance");
3447+
if declared.0 == "events_p_future" {
3448+
assert_ne!(declared, advanced, "catch-all did not advance");
3449+
} else {
3450+
assert_eq!(declared, advanced, "retired table was partition-managed");
3451+
}
34463452
}
34473453
let children: Vec<(String, String)> = sqlx::query_as(
34483454
"SELECT p.relname::text, c.relname::text FROM pg_inherits i \
34493455
JOIN pg_class c ON c.oid = i.inhrelid \
34503456
JOIN pg_class p ON p.oid = i.inhparent \
3451-
WHERE p.relname IN ('events', 'delivery_log')",
3457+
WHERE p.relname = 'events'",
34523458
)
34533459
.fetch_all(&pool)
34543460
.await
@@ -3460,7 +3466,10 @@ mod postgres_tests {
34603466
child.starts_with(&format!("{parent}_p2")) && !declared.contains(child)
34613467
})
34623468
.collect();
3463-
for (catch_all, bound) in &declared_bounds {
3469+
for (catch_all, bound) in declared_bounds
3470+
.iter()
3471+
.filter(|(catch_all, _)| catch_all == "events_p_future")
3472+
{
34643473
// The first month the declared catch-all served, from its
34653474
// `FOR VALUES FROM ('YYYY-MM-01 ...')` lower bound.
34663475
let parent = catch_all

0 commit comments

Comments
 (0)