Skip to content

buzz-db: drop the community_deletion_lock_key and profile_name_fields functions (contract) - #9598

Merged
TheSentinel454 merged 3 commits into
mainfrom
elrond/drop-plain-sql-functions
Nov 17, 2026
Merged

TheSentinel454 merged 3 commits into
mainfrom
elrond/drop-plain-sql-functions

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase 2 of retiring the two remaining plain SQL functions. Phase 1 moved their work into the relay:

No relay at or after #9397's merge (279a31da) calls either function. This PR drops them:

  • Migration 0093 runs DROP FUNCTION community_deletion_lock_key(UUID) and DROP FUNCTION profile_name_fields(TEXT) under a 5s lock_timeout, with no IF EXISTS and no CASCADE. If anything still depends on a function, the migration fails instead. Migrations 0029 and 0064 stay frozen. No database function calls either one any more: 0090 dropped the fence functions, which were the only SQL callers of the lock key.
  • Desired state: removes both schema/functions/ files and their schema.sql includes. Both boot paths stay catalog-equivalent (admin_schema_parity_between_desired_state_and_migrations).
  • Tests:
    • New migration_0093_drops_plain_sql_functions. It migrates to 0092, checks that both functions exist and that serving and deletion catalog validation pass, then runs 0093 and checks that both functions are gone and that validation still passes. This covers new code on either side of the drop.
    • The migration listing test pins 0093's statements and that it has no CASCADE.
    • desired_state_catalog_has_no_universal_fence_and_still_boots now asserts that both functions are absent.
    • Replaces the Rust-vs-SQL lock key parity test with community_deletion_lock_key_bytes_are_fixed, a unit test that maps fixed UUIDs (nil, max, and one with hex letters) to their exact keys. Older replicas and the repair-script key in docs/database.md build the same string, so a changed prefix or UUID format must fail a test.
    • Removes two relay test-schema wrappers (bridge.rs, ingest.rs) that forwarded community_deletion_lock_key to public. Writers no longer call it, and the wrapper's CREATE FUNCTION would fail once the function is gone.
  • Docs: docs/trigger-retirement-deployment.md gets a 0093 section with the required stop.

Deploy gate

Required stop: any relay build at or after 279a31da (#9397's merge, which follows #9396). relay-v0.3.0 does not contain it. A relay older than that which still serves after 0093 fails every write and deletion that takes the community deletion lock, with 42883 community_deletion_lock_key(uuid) does not exist, and its profile name search fails with 42883 profile_name_fields(text) does not exist. 0093 takes no table locks and needs no cleanup.

Migration number: #8696 and #9398 also propose 0093. Whichever lands second renumbers.

Review-Proven Rules

  • RPR Initial release — Sprout Nostr relay with enterprise extensions #2 (every path): I checked every reference on main and at the stop build 279a31da. At both, only test code reads either function: no boot, readiness, catalog or runtime query depends on them. Serving and deletion catalog validation pass before and after 0093, in the new test.
  • RPR feat: add desktop app #3 (falsifiable): removing the profile_name_fields drop from 0093 turns migration_0093_drops_plain_sql_functions red.
  • RPR feat: add desktop app #3 (lock key bytes): a changed prefix, .simple() UUID formatting, or uppercase formatting each turns community_deletion_lock_key_bytes_are_fixed red.

What got simpler

Two database functions, their desired-state files, a cross-language parity test and two test-only SQL wrappers are gone. After this PR, the only functions left in schema/functions/ are trigger functions.

Validation

Blox gate at 95ac71c8:

  • cargo fmt --all --check, and cargo clippy -p buzz-db -p buzz-relay --all-targets -D warnings.
  • buzz-db --lib unit tests: 216/216, including the migration listing test.
  • buzz-db Postgres tests (migration::, deletion::, nip_fi_binding:: postgres_tests): 130/130. These include migration_0093_drops_plain_sql_functions, admin_schema_parity_between_desired_state_and_migrations and deletion_surface_parity_between_migration_0029_and_schema_sql.
  • buzz-search profile_names* Postgres tests: 4/4, on a fully migrated database where profile_name_fields no longer exists.
  • The two relay tests whose test-schema wrapper this PR removes: 2/2.
  • Must-fail check: with the profile_name_fields drop removed from 0093, migration_0093_drops_plain_sql_functions fails.

Second Blox gate at e1b5513a (the lock key vector test):

  • cargo fmt --all --check, and cargo clippy -p buzz-db --all-targets -D warnings.
  • buzz-db --lib unit tests: 217/217.
  • Must-fail checks: a changed prefix, .simple() and uppercase UUID formatting each fail community_deletion_lock_key_bytes_are_fixed.

The first gate run found that deletion_surface_parity_between_migration_0029_and_schema_sql still expected community_deletion_lock_key in schema.sql. The second commit fixes that.

🤖 Generated with Claude Code

buzz-review-completed

… functions

Phase 2 of retiring the plain SQL functions. #9396 builds the deletion
lock key in Rust and #9397 reads profile names inline, and every relay
now runs a build with both, so no serving code calls either function.

Migration 0093 drops both, with a 5s lock_timeout and no CASCADE.
Migrations 0029 and 0064 stay frozen. The desired-state function files
and their schema.sql includes go too, along with the Rust-vs-SQL lock
key parity test and two test-schema wrappers that forwarded the old
function. docs/trigger-retirement-deployment.md names the required stop:
a relay build at or after 279a31d (#9397's merge).

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>
… the 0029 parity 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>
TheSentinel454 added a commit that referenced this pull request Nov 17, 2026
Main's fence-retirement tests asserted that communities_deletion_tombstone
still exists. Migration 0093 drops it, so they now assert it is absent.
The lock function stays until #9598.

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 marked this pull request as ready for review November 17, 2026 03:31
@TheSentinel454
TheSentinel454 requested a review from a team as a code owner November 17, 2026 03:31
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 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: c0ce4982fcbbc379255fde6762487d5808d8d2b4...e1b5513a5b269e2f68857707086af1d41df54c25
  • 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 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 run.

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

The deleted SQL parity test was the only check that the key format
matched something outside the Rust helper. Older replicas and operator
repair scripts build the same string, so pin it with fixed UUID to key
vectors. A UUID with hex letters makes uppercase or simple formatting
fail, and every vector fails on a prefix change.

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 17, 2026
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 17, 2026
@TheSentinel454
TheSentinel454 merged commit 4e8f836 into main Nov 17, 2026
90 checks passed
@TheSentinel454
TheSentinel454 deleted the elrond/drop-plain-sql-functions branch November 17, 2026 18:44
TheSentinel454 added a commit that referenced this pull request Nov 17, 2026
… test call) (#9616)

## Summary

Main has two migrations numbered `0093`:

- `0093_push_gateway_installation_platform.sql` from #9560
- `0093_drop_plain_sql_functions.sql` from #9598

The file names differ, so GitHub showed no conflict between the PRs.
sqlx applies the first version-93 migration and then rejects the second
as a changed migration 93. Every migrate run on main fails, including
relay startup with auto-migration on.

This PR moves #9598's migration to `0094`:

- `git mv migrations/0093_drop_plain_sql_functions.sql
migrations/0094_drop_plain_sql_functions.sql`. The SQL is unchanged.
- `embedded_migrator_contains_consolidated_initial_schema` now expects
94 migrations, with the function drop at version 94.
- The Postgres test is renamed to
`migration_0094_drops_plain_sql_functions`. It finds the migration by
description, so its logic is unchanged.
- `docs/trigger-retirement-deployment.md` now names `0094`.

#9560's `0093` keeps its number. It reached main first and may already
be applied on deployments that auto-migrate.

## Second break on main: `update_channel` call sites

Main's buzz-db lib tests also stopped compiling. #9581 added a `sender`
argument to `update_channel`, and #8320's cross-community test
(`deletion.rs`) landed in parallel with the old three-argument call.
This PR passes the channel creator as the sender. The test only renames
an open channel, so the private-to-open rule does not apply.

## Deployments

No deployment has applied #9598's `0093`: no image built from main after
#9598 has rolled out yet. A database that applied #9560's `0093` applies
`0094` next. Do not promote any image built from `4e8f8365` (the #9598
merge) or later until this PR merges.

## What got simpler

Nothing. This is a renumber and a test call fix only.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

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>
TheSentinel454 added a commit that referenced this pull request Nov 17, 2026
## Summary

Main's user content cleanup still calls the SQL function
`community_deletion_lock_key`. Migration `0094` (#9598) drops it. On any
database at `0094`, every user-deletion content batch fails with `42883
function community_deletion_lock_key(uuid) does not exist`.

#9363 added this caller after #9396 moved the key to Rust. This PR binds
the Rust-built key with `hashtextextended($1, 0)`, as every other caller
does.

- `content_batches/execute.rs`: the batch's exclusive advisory lock uses
the Rust key.
- `content_batches/safety_postgres_tests.rs`: the test blocker takes the
same lock the same way.
- `docs/trigger-retirement-deployment.md`: builds from #9363 up to this
PR are not valid stops before `0094`.

Rebased onto main `e894d75d`. The renumber and the `update_channel`
test-call fixes this PR first carried are already on main through #9616,
so they are gone from this PR.

Deployed relays are unaffected: the deployed build predates #9363.

## Tests

The 17 `user_deletion::content_batches` PostgreSQL tests fail on main at
`0094` with the error above. This PR makes them pass.

## What got simpler

One fewer SQL-side copy of the lock key. Every caller now builds the key
in Rust.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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>
wpfleger96 added a commit that referenced this pull request Nov 17, 2026
…e-recovery

* origin/main: (60 commits)
  Clean up account records and refresh member lists (#9364)
  perf(mobile): save own thread interest once per unread catch-up (#9614)
  buzz-db: fix main (renumber the function drop to 0094, update_channel test call) (#9616)
  feat(relay): name the agent whose add policy refuses a DM (#9601)
  buzz-db: drop the community_deletion_lock_key and profile_name_fields functions (contract) (#9598)
  fix(deps): clear chrono, humantime and zip advisories from the dependency policy (#9609)
  docs: define mobile diagnostic reporting (#9600)
  build(mobile): link iOS plugins through Swift Package Manager (#9597)
  feat(push-gateway): enroll Android installations and send FCM wakes (#9560)
  perf(mobile): cache and animate custom emoji in the iOS picker (#9479)
  fix(ios): end each bold or strikethrough run at its first closing marker (#9559)
  Apply the private-to-open rule in update_channel too (#9581)
  Add real content cleanup for users and agents (#9363)
  Keep transparency in mobile avatar photo crops (#9319)
  fix(mobile): read presence for a person shown again while still covered (#9595)
  buzz-db: check membership, agent-owner and channel references in app code (#9404)
  buzz-db: enforce five single-table guards in app writers (phase 1) (#8320)
  docs(mobile): add REVIEWING.md with mobile review principles (#9298)
  buzz-db: check workflow references in app code before FK retirement (#9399)
  fix(relay): enforce channel owner precedence (#9592)
  ...

Signed-off-by: Will Pfleger <wpfleger@block.xyz>

# Conflicts:
#	mobile/lib/features/channels/channel_actions_sheet.dart
#	mobile/lib/shared/read_state/read_state_manager.dart
TheSentinel454 pushed a commit that referenced this pull request Nov 17, 2026
## Summary
Migration 0095 drops the 0032 channel roster trigger
(`trg_events_guard_channel_roster_snapshot`) and its function
(`guard_channel_roster_snapshot()`).

The trigger repeats a check that the relay already does in Rust. Every
kind:39002 roster writer checks the roster against the channel's
membership before it saves it (#8316). Since #8611, no relay requires
the trigger at startup. This PR is the last step of the trigger
retirement sequence in `docs/database.md`.

This PR was split out of #8494 so the migration can roll out by itself.
A relay from this PR does not change how it stores or publishes roles,
and it has no new startup check. It serves correctly whether or not 0095
has run. #8494 stacks on this PR and must not merge until 0095 has run
in every environment.

## Details
- **Migration 0095.** `DROP TRIGGER` and `DROP FUNCTION`, with
`lock_timeout = '1s'` and `statement_timeout = '5s'` as in 0049. `DROP
TRIGGER` takes `ACCESS EXCLUSIVE` on each `events` partition in turn, so
event reads and writes block while it runs. A timeout rolls it back with
no change, and it can be retried.
- **Desired-state schema.**
`schema/functions/guard_channel_roster_snapshot.sql` is removed. This
was the last trigger on `events`, so `schema/triggers/events.sql` and
its include go too, as do the pre-attach trigger drops in
`scripts/reconcile-schema-after-pgschema.sql`.
- **Operator guide.** #8326 added
`docs/trigger-retirement-deployment.md` for migrations 0089–0091. (0092
from #9365 and 0093 from #9560 drop nothing; 0094 from #9598 drops two
plain SQL functions and has its own section there.) This PR adds 0095 to
it: its row, the two ways an older relay fails, the migrate check, and
the parent trigger a pgschema deployment must drop first. The Helm chart
README names the required stop and points to that guide.
- **Tests.** Tests that compared the trigger with the Rust check, or
that disabled the trigger first, now test the Rust check alone. Tests
that only exercised the trigger against a simulated pre-#8316 writer are
removed. The 0075 invite upgrade test now migrates to 0075 exactly.

## Rollout
**Required stop: the stop build in
`docs/trigger-retirement-deployment.md`** (a relay build at or after
`68785206`, the merge of #8325). That build contains #8316 (the app-side
roster check) and #8611 (no startup trigger check), so it covers 0095
too. `relay-v0.3.0` contains #8316 and #8611 but not #8325, so it is no
longer enough on its own: any build with 0095 also has 0089–0091.
Without the stop, an untagged `main` build between 0032 and #8611
refuses to start once the trigger is gone, and a relay without #8316 can
save stale kind:39002 snapshots (`docs/database.md` Rule 5).

**Merge gate.** Every push to main publishes relay `:main` images, and
the Helm chart defaults to `migrate.autoMigrate=true`. Do not merge this
PR until the stop build or later runs on every serving and rollback
target. That is the same gate #8326 had for 0089–0091.

After that, either way works:
- With `autoMigrate=true`, the first relay from this PR applies 0095 at
startup.
- With `autoMigrate=false`, run `buzz-admin migrate` when convenient.
Relays from this PR serve with or without 0095.

As with every new migration, an older binary with auto-migration on
refuses a database that has 0095 (sqlx `VersionMissing`). A rollback
past this release needs auto-migration off (`docs/database.md`).

## What happens next
#8494 computes the `member`/`bot` label at read time. The 0032 trigger
compares labels with the stored role exactly, so it would refuse those
rosters. #8494 adds a startup check that refuses to serve while the
trigger is installed. Merge it only after 0095 has run everywhere.

### Testing
- `migration_0095_retires_the_roster_trigger`: on a database migrated
through 0094, the trigger and function are installed. After the
remaining migrations, both are gone, and a raw kind:39002 insert that
does not match membership is accepted. It fails if 0095 does not drop
them.
- `embedded_migrator_contains_consolidated_initial_schema` pins 95
migrations and the 0095 statements, and checks that the desired-state
schema no longer installs the function.
-
`migration_schema_desired_pgschema_reconcile_matches_populated_upgrade`:
its fixture drops each retired parent trigger before pgschema runs
(pgschema drops partition copies before the parent, which PostgreSQL
refuses with 2BP01). It now drops the roster trigger too.
- Locally at this head: `cargo check`, `cargo fmt --check`, and 245/245
buzz-db unit tests pass; 760/764 buzz-db Postgres tests pass. The four
`event_follow_up_contract` tests fail the same way on `main` locally and
pass in CI. CI runs clippy and the full PostgreSQL lane.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
wpfleger96 added a commit that referenced this pull request Nov 18, 2026
…c-spec-mobile

* origin/main: (37 commits)
  buzz-db: drop the five single-table guard triggers (BUZZ-318 phase 2) (#9398)
  push-gateway: lock expired installations before reaping (#9627)
  Retire the 0032 roster trigger in migration 0095 (#8696)
  fix(db): hard-delete superseded relay-signed lists (#9586)
  Add community-scoped user and agent profile cleanup (#9580)
  fix(sdk): timestamp channel messages with millisecond offsets (#9548)
  Check product_feedback's community in the writing transaction (#9608)
  buzz-db: stop calling the dropped lock-key function in SQL (#9615)
  Clean up account records and refresh member lists (#9364)
  perf(mobile): save own thread interest once per unread catch-up (#9614)
  buzz-db: fix main (renumber the function drop to 0094, update_channel test call) (#9616)
  feat(relay): name the agent whose add policy refuses a DM (#9601)
  buzz-db: drop the community_deletion_lock_key and profile_name_fields functions (contract) (#9598)
  fix(deps): clear chrono, humantime and zip advisories from the dependency policy (#9609)
  docs: define mobile diagnostic reporting (#9600)
  build(mobile): link iOS plugins through Swift Package Manager (#9597)
  feat(push-gateway): enroll Android installations and send FCM wakes (#9560)
  perf(mobile): cache and animate custom emoji in the iOS picker (#9479)
  fix(ios): end each bold or strikethrough run at its first closing marker (#9559)
  Apply the private-to-open rule in update_channel too (#9581)
  ...

Signed-off-by: Will Pfleger <wpfleger@block.xyz>

This branch was previously deployed

1 inactive deployment
codex-review — e1b5513a Deployed Nov 17, 2026 by TheSentinel454 via Run Codex Security Review #15656
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.

2 participants