Skip to content

Drop the unused delivery_log and subscriptions tables - #9772

Open
TheSentinel454 wants to merge 7 commits into
mainfrom
elrond/drop-delivery-tables
Open

TheSentinel454 wants to merge 7 commits into
mainfrom
elrond/drop-delivery-tables

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge order: do not merge until #9746 is deployed to every environment. Deployments that apply schema out of band apply 0106 before the code that includes it.

Summary

Contract step after #9746. Migration 0106 drops delivery_log, subscriptions, and the three enums only they used (delivery_method, subscription_status, pause_reason). The tables were created for a delivery feature that was never built. No code uses them since #9746, and no foreign key touches them since 0102–0104.

Required stop: #9746 must be deployed everywhere before this migration runs. An older relay or deletion executor still selects from these tables.

Changes

  • migrations/0106_drop_delivery_tables.sql: DROP TABLE IF EXISTS and DROP TYPE IF EXISTS, with the same lock budgets as 0102–0104. No CASCADE, so an unexpected dependent fails the migration.
  • schema/: removes the two tables, the delivery_log partitions, and the three types. .pgschemaignore and scripts/reconcile-schema-after-pgschema.sql drop their delivery_log parts. scripts/drop-partitioned-foreign-keys.sql touches delivery_log only when it still exists (reused test databases).
  • Community deletion (crates/buzz-db/src/store/deletion.rs):
    • The catalog is an exact set again. A live delivery_log or subscriptions is an unknown tenant table and blocks deletion.
    • RETIRING_SCOPED_TABLES becomes DROPPED_SCOPED_TABLES. Its only use is validate_approved_schema, so a request approved before 0106 still executes after it.
  • Docs: docs/database.md "Retiring a tenant-owned table" now describes the two-release process. ARCHITECTURE.md drops the table row.
  • scripts/cutover/1321_backfill_default_community.sql is unchanged. It builds its own copy of 0001, so its targets still exist in that flow.

What got simpler

  • The present-or-absent handling for retiring tables is gone from the catalog check, the purge, and verification.
  • Three retiring-table tests and their helpers are removed.
  • Net 538 lines removed, 184 added.

Testing

  • embedded_migrator_contains_consolidated_initial_schema checks 0106's statements.
  • New dropped_scoped_tables_are_rejected_as_unknown_when_live.
  • approved_schema_tolerates_only_dropped_tables_vanishing covers a pre-0106 approval.
  • Tests that migrate through an older version and check the catalog now drop the tables by hand, or assert the exact drift.

The operator database ownership script that checks for delivery_log as an anchor gets a matching change outside this repo. That change is safe to land first.

🤖 Generated with Claude Code

@TheSentinel454
TheSentinel454 marked this pull request as ready for review November 20, 2026 14:23
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 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: 2074adaa8542dd0094ba12c0b11b8a7402601cbc...852660cd86c2163b1ac849c384b71e96495e6b42
  • 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 findings identified 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 and tests were not executed, as requested.

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

@joahg joahg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Checked at this head: nothing outside migration 0105 and the dropped-table tests still reads or writes delivery_log, subscriptions or the three enums. Crates, migrations, schema, scripts, docs and ARCHITECTURE are clean, there is no .sqlx metadata, and the only remaining mentions are the deliberate DROPPED_SCOPED_TABLES approval-compat list and tests. The drops are CASCADE-free, so an unexpected dependent fails the migration, and the tables were never written by a release, so having no down migration is fine. CI is green, including the PostgreSQL, relay e2e and populated-upgrade tests. Two notes: #9746 is merged but must be deployed everywhere before 0105 runs, as the PR says, and open #9794 also adds a 0105_* migration (main is at 0104), so whichever merges second needs to renumber to 0106.

@wpfleger96 wpfleger96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Automated review at c462097b: changes requested for one documentation gap. The migration and code look right.

The migration, the deletion catalog change and the handling of approvals made before the drop all hold up. A live run on a throwaway Postgres confirmed it. Migrations through 0104 plus 0105 apply with empty and populated tables, and a rerun succeeds. An unexpected view or column on the dropped tables or types makes 0105 fail with 2BP01 and keeps everything. A held lock ends the attempt with 55P03 in about 0.35s, and a retry succeeds. pgschema plan after 0105 matches the base.

Blocking: the chart's upgrade docs don't name the new required stop. docs/database.md Rule 5 says the release notes must name the release to stop at before a contract migration. deploy/charts/buzz/README.md "Upgrades" is where the earlier stops live ("Required stop before migrations 0089–0091, 0095 and 0096", "Required stop before migration 0100"). It also says that outside those, helm upgrade is the entire upgrade procedure. 0105 needs #9746 deployed first, but neither PR adds that stop there.

This matters for Helm users because no tagged relay release contains #9746 yet. The latest is relay-v0.3.0, so the next tag would ship #9746 and 0105 together, and a deployment on 0.3.0 has nothing to stop at. relay-v0.3.0 still boots after 0105, since its serving check needs only communities, community_serving_write_leases and community_deletion_requests. But on it, community deletion fails its exact catalog check, because delivery_log and subscriptions are in its EXPECTED_SCOPED_TABLES. User deletion's account batches still query the dropped tables, and startup partition maintenance logs "Failed to ensure partitions". That happens on old pods during a rolling upgrade, and indefinitely after a rollback to 0.3.0. No data is lost, but deletions fail.

Suggested fix: add a "Required stop before migration 0105" paragraph to the chart README, modelled on the 0100 entry. It should name the stop build (sha-7e94503 or later, or the first tagged relay release containing #9746). It should say that a rollback after 0105 must target that build or later, with migrate.autoMigrate=false. And it should say what an older build loses.

Non-blocking: migration_0105_drops_populated_delivery_tables (crates/buzz-db/src/runtime/migration.rs:4348) checks both tables but only delivery_method of the three dropped types. Adding to_regtype('subscription_status') and to_regtype('pause_reason') would cover the rest.

@TheSentinel454

Copy link
Copy Markdown
Contributor Author

🤖 @wpfleger96 Fixed in b89256be90d0cd0619effe3c3bf7fad11d232323: the chart README now has a "Required stop before migration 0105" paragraph. It names sha-7e94503 (or the first tagged relay release with #9746) as the stop, says what older builds lose, and gives the migrate.autoMigrate=false rollback. The populated 0105 test now checks all three dropped types.

@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
TheSentinel454 and others added 6 commits November 20, 2026 14:41
Migration 0105 drops both tables and the three enums only they used.
manifest, pgschema ignore list and reconcile script drop their
delivery_log parts.

Community deletion's catalog is an exact set again. A frozen approval
from before 0105 may still list the two tables, and
validate_approved_schema accepts that they are gone.

Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pgschema drops the fence function before the tables whose triggers
still use it. A deployment applies 0105 first, so the fixture does too.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
- Restore the executor check that an approval frozen with the dropped
  tables still reaches RetentionPending on its original digest.
- Test that 0105 drops populated tables, and state the discard decision.
- Apply 0105 before pgschema in start-relay-for-tests.sh.
- docs: run the rollback build with auto-migration off after the drop.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Also check all three dropped types in the populated 0105 test.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Main took 0105 for the push gateway in-flight column (#9802). The drop
moves to 0106. Every reference, the count test and the chart README
required stop now name 0106.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
@TheSentinel454
TheSentinel454 force-pushed the elrond/drop-delivery-tables branch from b89256b to bbaaaf3 Compare November 20, 2026 19:42
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026

@wpfleger96 wpfleger96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 No blocking issues at bbaaaf3d. The upgrade notes now name the required stop at #9746, which was the one blocker last time, and the drop is correctly renumbered to 0106 after main took 0105.

  • Upgrade path, run for real: a relay built from the base migrated a fresh database through 0105, then took one row in each of delivery_log and subscriptions. The relay built from this head then applied 0106 on startup. Both tables, all six delivery_log partitions and the three enums are gone, 0105's checksum is unchanged, and the relay served /_readiness, /health and NIP-11.
  • Renumber: no stale 0105 reference to the drop remains in code, tests, docs, scripts or the description. Main's 0105 only adds a column to push_gateway_delivery_request_replays, so it doesn't depend on the dropped objects, and scripts/start-relay-for-tests.sh still drops the tables before pgschema runs.
  • Stop and rollback: 7e94503f is #9746's merge commit, and the rollback steps match the neighboring 0100 entry.

Two minor wording points in the new README paragraph are inline.

Comment thread deploy/charts/buzz/README.md Resolved
Say that the failures on older builds lose no data, but 0106 discards
any rows left in the tables. Scope the user-deletion failure to builds
after relay-v0.3.0, which has no user-deletion executor.

Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
@github-actions github-actions Bot removed the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 20, 2026

@wpfleger96 wpfleger96 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 Automated review of 852660cd. Clear.

The one new commit rewords the 0106 required-stop paragraph in deploy/charts/buzz/README.md and resolves both wording notes from the last review:

  • It now says the failures on older builds lose no data and, separately, that 0106 discards any rows left in the tables, with a prompt to export them first.
  • User-deletion failure is scoped to builds after relay-v0.3.0. That matches the source: relay-v0.3.0 has only the user-deletion preparation modules, and the executors (#9363, #9364, #9365, #9580) landed between that tag and 7e94503f. relay-v0.3.0 is still covered by "builds before commit 7e94503f".

The rest of the branch is unchanged from bbaaaf3d, which was reviewed and run through the populated upgrade earlier. CI is green on this head.

This branch was successfully deployed

1 active deployment
codex-review — 852660cd Deployed Nov 20, 2026 by TheSentinel454 via Run Codex Security Review #16979
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.

3 participants