Skip to content

fix(db): undo migration 0097 - #9710

Merged
TheSentinel454 merged 4 commits into
mainfrom
elrond/unwind-0097
Nov 19, 2026
Merged

TheSentinel454 merged 4 commits into
mainfrom
elrond/unwind-0097

Conversation

@TheSentinel454

@TheSentinel454 TheSentinel454 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Migrations 0098–0100 undo migration 0097 (community artifact expand). The declared schema goes back to its shape before #9650.

#9650 added 0097. The revert, #9689, removed the feature but kept 0097 byte for byte, because databases that auto-migrated recorded its checksum. No code on main reads or writes what 0097 added. This PR removes it with forward migrations, as docs/database.md requires ("Never edit a merged migration. Fix forward.").

artifact_heads.channel_id gets NOT NULL back in the three steps from Adding NOT NULL to a populated table:

  • 0098 checks that the artifact head key is (community_id, artifact_id), then adds CHECK (channel_id IS NOT NULL) NOT VALID.
  • 0099 validates the check under SHARE UPDATE EXCLUSIVE, so channel artifact reads and writes continue.
  • 0100 sets NOT NULL from the validated check (no scan), drops the check, drops artifact_heads_live_type, artifact_heads_scoped_identity and artifact_revisions_scoped_identity, and drops artifact_heads.scope, artifact_revisions.scope, artifact_revisions.community_event, artifact_revisions.redacted and communities.artifact_type_policies.

The primary keys don't change. 0097 never changed them.

Review checklist (docs/database.md)

Tests

  • admin_schema_parity_between_desired_state_and_migrations compares artifact_heads, artifact_revisions and communities across the desired-state and migrated paths. It fails without 0100.
  • populated_artifact_tables_auto_migrate_through_every_migration checks that a channel head and revision written before 0097 survive with the same channel and event.
  • artifact_unexpand_validates_while_channel_heads_are_written: 0099 completes while a channel head write is still open. It fails if 0099 sets NOT NULL directly.
  • artifact_unexpand_refuses_scoped_head_key: 0098 stops on the scoped key and leaves 0097's columns in place.

What got simpler

The schema loses 5 unused columns and 3 unused indexes. artifact_heads.channel_id is required again, as the channel code assumes.

🤖 Generated with Claude Code

TheSentinel454 and others added 3 commits November 19, 2026 10:12
#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>
@TheSentinel454 TheSentinel454 changed the title fix(db): undo migration 0097 with 0098 fix(db): undo migration 0097 Nov 19, 2026
@TheSentinel454
TheSentinel454 marked this pull request as ready for review November 19, 2026 15:29
@TheSentinel454
TheSentinel454 requested a review from a team as a code owner November 19, 2026 15:29
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>
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 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: 7d116da335a10a6f51762b104dc44d2d788c3117...d80c3d085a01d03b4136b8419b525f1dc2d44ca3
  • 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 regressions found 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, tests, and database migrations were not executed.

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

@github-actions github-actions Bot added codex-security-review-current The posted Codex security review matches its recorded range. and removed codex-security-review-current The posted Codex security review matches its recorded range. labels Nov 19, 2026
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;

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.

🤖 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 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 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.

@TheSentinel454
TheSentinel454 merged commit 9ea57cb into main Nov 19, 2026
94 checks passed
@TheSentinel454
TheSentinel454 deleted the elrond/unwind-0097 branch November 19, 2026 18:18
cshtdd added a commit that referenced this pull request Nov 19, 2026
…-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>
TheSentinel454 added a commit that referenced this pull request Nov 19, 2026
## 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>
wpfleger96 added a commit that referenced this pull request Nov 19, 2026
…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>

This branch was successfully deployed

1 active deployment
codex-review — d80c3d08 Deployed Nov 19, 2026 by TheSentinel454 via Run Codex Security Review #16303
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