Repository navigation
fix(db): undo migration 0097 - #9710
Conversation
#9650 added migration 0097 for community-scoped artifacts. The revert (#9689) removed the feature but kept 0097, because databases that auto-migrated recorded its checksum. No code reads or writes the columns it added. 0098 drops 0097's three indexes and five columns and makes artifact_heads.channel_id NOT NULL again. The declared schema returns to its pre-#9650 shape. A database that never applied 0097 nets to no change when it applies 0097 and 0098 together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Review found that SET NOT NULL scanned artifact_heads under ACCESS EXCLUSIVE. docs/database.md requires three steps instead: - 0098 adds a NOT VALID check; - 0099 validates it under SHARE UPDATE EXCLUSIVE, so writes continue; - 0100 sets NOT NULL from the validated check and drops 0097's indexes and columns. 0098 also refuses a database whose artifact head key is the scoped key from the removed operator contract, before any cleanup runs. The migrations name #9689 as a required stop, because relays built from #9650 read the dropped column. Tests now bind the surviving head's exact channel and event, and check its revision. New tests check that 0099 runs beside an open head writer and that 0098 refuses the scoped key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Relay images built from #9650 up to, but not including, #9689 read the columns 0100 drops. The chart's upgrade notes now tell operators to move every pod, job and rollback target to sha-a406191 or later first, and how to roll back after 0100. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Luke Tornquist <tornquist@squareup.com>
🔐 Codex Security Review
Review SummaryOverall Risk: NONE
FindingsNo concrete security, correctness, or reliability findings were identified. Notes
Generated by Codex Security Review | |
| WHERE c.conrelid = 'artifact_heads'::regclass AND c.contype = 'p') | ||
| IS DISTINCT FROM ARRAY['community_id', 'artifact_id'] THEN | ||
| RAISE EXCEPTION 'artifact_heads primary key is not (community_id, artifact_id); recover this database as described in #9689 before migrating'; | ||
| END IF; |
There was a problem hiding this comment.
🤖 Minor, non-blocking: this error, and the chart README's new upgrade note, tell the operator to recover the database "as described in #9689". #9689's Compatibility section only lists the two checks (the primary key is on (community_id, artifact_id), no scope = 'community' rows) and says a database that fails them "needs a separate recovery step". It never describes that step, so an operator who hits this error has nothing to follow. Either write the recovery here and in the README, or drop the pointer and say plainly that this database needs manual recovery before upgrading. Only databases that ran #9650's operator contract script can hit this, so it's rare.
wpfleger96
left a comment
There was a problem hiding this comment.
🤖 No blocking concerns at d80c3d08. Migrations 0098–0100 follow the NOT NULL recipe in docs/database.md, the declared schema matches, and no runtime code on main still uses the dropped columns or indexes. Two non-blocking notes: the recovery pointer comment on 0098 still applies, and a test that seeds a head with a null channel_id through 0097 and asserts the migration stops at 0099 with the columns and row intact would make that fail-closed claim executable.
…-workflow-verified-mentions * 'main' of https://github.com/block/buzz: (21 commits) chore: require relay owner review for the relay and db crates (#9728) fix(mobile): align Huddle cards and preserve conversation navigation (#9713) Match mobile mention chips to desktop styling (#9706) feat(relay): push mentions to people outside a listed channel (#9623) fix(db): undo migration 0097 (#9710) fix(mobile): keep glass controls mounted and the wide thread push parallax (#9726) fix(mobile): stabilize Duo chat switching and sheet layering (#9717) Require relay schema owner review for migrations and schema (#9708) fix(relay): resurface a hidden DM when someone else messages it (#9678) fix(deploy): pin self-host installs to relay 0.3.0 (#9714) fix(mobile): keep open shared sessions in Solo (#9704) fix(mobile): align channel indicators and Duo section menus (#9703) fix(mobile): allow person mentions in Solo chats (#9705) fix(mobile): let code scroll under the code block copy button (#9612) Transcribe Bestie hold recordings into text on device (#9645) feat(cli): show and search verified identity in users get (#9647) fix(mobile): keep agent poster up until the iOS video draws (#9688) test(relay): stop bridge cancel_fixture tests timing out on the first replica connect (#9691) Revert "feat(relay): support community-scoped NIP-AR artifacts" (#9689) feat(relay): add conditional Solo member role updates (#9667) ... Signed-off-by: Camilo Sanchez <camilos@squareup.com>
## Summary Retire the last foreign key in the push gateway schema: `push_gateway_delegations.installation_id → push_gateway_installations(id)`. This follows `docs/database.md` Rule 2 and the relay FK retirement work (#9399, #9404). - **Gateway migration 0008** drops the constraint. - **Relay migration 0101** drops the relay's legacy copy (Rule 4: gateway schema changes go in both). `schema/tables/public/push_gateway_delegations.sql` loses the inline `REFERENCES`. ## Required stop Every gateway and rollback target must run #9627 (`44cdd9fe`) or later before this merges and deploys. #9627 makes the reaper lock expired installations before it deletes their delegations. Without the FK, an older reaper can leave an orphaned delegation. This is step 2 of the Rule 5 retirement sequence; #9627 is step 1. ## Why the app already enforces the reference | Path | Check | |---|---| | `upsert_delegation` (only delegation insert) | Locks the installation `FOR UPDATE` in the same transaction; rejects a missing or revoked one. | | `create_installation` (replaces expired installations) | Locks the matching installations `FOR UPDATE`, deletes their delegations, then the installations. | | `reap_expired` | Locks expired installations `FOR UPDATE`, deletes their delegations, then the installations (#9627). | | `authorize_delivery` | Reads the installation through the delegation; a missing installation is `Rejected`. | | `revoke_delegation` | Updates the delegation only; an orphan has no effect. | | `revoke_installation`, `rotate_endpoint`, `advance_assertion_counter` | Update the installation; they never delete it. | The relay never reads or writes the `push_gateway_*` tables (the gateway requires its own database), so dropping the relay copy changes no relay behavior. ## Tests The gateway tests run against the migrated schema, which no longer has the FK, so they prove the app check. - `migrated_schema_has_no_foreign_keys` (new): the gateway schema has no foreign keys after migrations. It fails if gateway migration 0008 is removed. - `delegation_for_missing_installation_is_rejected` and `reaper_deletes_delegation_committed_while_it_waits` (from #9627) now run without the FK. - `reaper_retains_revocation_tombstones_until_authority_expiry`: its hand-built schema drops the FK too. - Relay: `push_gateway_delegations` joins the constraint parity check in `admin_schema_parity_between_desired_state_and_migrations`, and the migration count test covers 0101. ## Validation Blox at `33f7df90` (before the rename to 0101; CI covers the rebased head): - `cargo fmt --check`, clippy (`buzz-push-gateway`, `buzz-db`, all targets), gateway unit tests, `buzz-db` migration unit tests: pass. - `scripts/postgres-test-run.sh -p buzz-push-gateway --lib --tests`: 16/16 pass. - `buzz-db` Postgres tests for migrations, parity, push, floor retirement and retained guards: 56/56 pass, including `admin_schema_parity_between_desired_state_and_migrations`. - Must-fail check: with gateway migration 0008 removed, `migrated_schema_has_no_foreign_keys` fails (1 foreign key vs 0). ## Coordination - On main after #8696, #9398 and #9710 (relay 0095–0100). #9627 shipped this PR's reaper fix and tests separately, so this PR is the schema drop only. - Renumbered to relay 0101 after #9710 took 0098–0100 (rename only; file contents unchanged). #9690 and #9621 also add a relay 0098; whichever merges second renumbers. - #8328 adds the gateway's declarative schema with the inline FK. Whichever PR merges second removes it there. ## What got simpler One fewer database object. Every gateway reference check now lives in one place: the gateway's own transactions. buzz-review-completed 🤖 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>
…c-spec-mobile * origin/main: push-gateway: drop the delegation → installation foreign key (#9610) Match desktop unread cues on mobile channel rows (#9715) feat(mobile): refresh Huddle speaking styles and iOS controls (#9716) feat(cli): add raw query and publish escape-hatch commands (#9653) fix(mobile): only say "Community changed" when the community changed (#9156) chore: require relay owner review for the relay and db crates (#9728) fix(mobile): align Huddle cards and preserve conversation navigation (#9713) Match mobile mention chips to desktop styling (#9706) feat(relay): push mentions to people outside a listed channel (#9623) fix(db): undo migration 0097 (#9710) Signed-off-by: Will Pfleger <wpfleger@block.xyz>
What
Migrations
0098–0100undo migration0097(community artifact expand). The declared schema goes back to its shape before #9650.#9650 added
0097. The revert, #9689, removed the feature but kept0097byte for byte, because databases that auto-migrated recorded its checksum. No code onmainreads or writes what0097added. This PR removes it with forward migrations, asdocs/database.mdrequires ("Never edit a merged migration. Fix forward.").artifact_heads.channel_idgetsNOT NULLback in the three steps from AddingNOT NULLto a populated table:0098checks that the artifact head key is(community_id, artifact_id), then addsCHECK (channel_id IS NOT NULL) NOT VALID.0099validates the check underSHARE UPDATE EXCLUSIVE, so channel artifact reads and writes continue.0100setsNOT NULLfrom the validated check (no scan), drops the check, dropsartifact_heads_live_type,artifact_heads_scoped_identityandartifact_revisions_scoped_identity, and dropsartifact_heads.scope,artifact_revisions.scope,artifact_revisions.community_event,artifact_revisions.redactedandcommunities.artifact_type_policies.The primary keys don't change.
0097never changed them.Review checklist (docs/database.md)
0097) and the code revert in Revert "feat(relay): support community-scoped NIP-AR artifacts" #9689.sha-a406191) or later before0100runs. The chart's upgrade notes (deploy/charts/buzz/README.md) say this, along with how to roll back with auto-migration off. No tagged relay release contains feat(relay): support community-scoped NIP-AR artifacts #9650. Only rolling images fromeebf62b6up to, but not including,a4061916are affected. Relays built from feat(relay): support community-scoped NIP-AR artifacts #9650 itself readartifact_heads.scopeand write withON CONFLICTonartifact_heads_scoped_identity. Releases before feat(relay): support community-scoped NIP-AR artifacts #9650 never read these objects.0098refuses a database whose artifact head key is the scoped key from feat(relay): support community-scoped NIP-AR artifacts #9650's removed operator contract script or declared schema. That database needs the recovery in Revert "feat(relay): support community-scoped NIP-AR artifacts" #9689's Compatibility section.0099fails if any head has a nullchannel_id. Both stop before any cleanup.migrations/andschema/tables/public/(artifact_heads.sql,artifact_revisions.sql,communities.sql). No reconcile-script or gateway change applies.lock_timeout = '5s'andstatement_timeout = '30s'. No index is built.Tests
admin_schema_parity_between_desired_state_and_migrationscomparesartifact_heads,artifact_revisionsandcommunitiesacross the desired-state and migrated paths. It fails without0100.populated_artifact_tables_auto_migrate_through_every_migrationchecks that a channel head and revision written before0097survive with the same channel and event.artifact_unexpand_validates_while_channel_heads_are_written:0099completes while a channel head write is still open. It fails if0099setsNOT NULLdirectly.artifact_unexpand_refuses_scoped_head_key:0098stops on the scoped key and leaves0097's columns in place.What got simpler
The schema loses 5 unused columns and 3 unused indexes.
artifact_heads.channel_idis required again, as the channel code assumes.🤖 Generated with Claude Code