Repository navigation
Conversation
soft_delete_channel sets deleted_at but keeps participant_hash, while find_dm_in only matches deleted_at IS NULL. Reopening a DM for the same participants after a delete finds nothing, inserts a new row and hits idx_channels_dm_hash on the deleted row, so the pair can never open a DM again. Make the unique index partial over deleted_at IS NULL (migration 0105, schema/tables/public/channels.sql). Signed-off-by: flowq-C <134304440+flowq-C@users.noreply.github.com>
🔐 Codex Security Review
|
joahg
left a comment
There was a problem hiding this comment.
🤖 No blocking issues found. The new deleted_at IS NULL predicate matches find_dm_in and claim_dm_identity, which already filter on live rows, and open_dm relies on the 23505 from the index (no ON CONFLICT target), so lookup and uniqueness now agree. The migration is safe on existing data (the new index covers a strict subset of the old one's rows, so it cannot fail on current data), it runs in one transaction with lock and statement budgets, and the schema file is updated to match. The regression test covers open, delete, reopen, and a third open reusing the new DM. Heads-up: draft #9772 also adds migrations/0105_* and edits the migration count assertion in runtime/migration.rs, so whichever lands second needs to renumber. This PR is from outside the Buzz maintainer team, so a human Buzz maintainer needs to review and approve it.
Fixes #9793
What
Migration
0105rebuildsidx_channels_dm_hashasUNIQUE (community_id, participant_hash) WHERE participant_hash IS NOT NULL AND deleted_at IS NULL.schema/tables/public/channels.sqlcarries the same definition, and the migrator count test inruntime/migration.rsnow expects 105 migrations.Why
soft_delete_channelkeepsparticipant_hash, whilefind_dm_inonly matches live rows. After a DM is deleted, reopening it for the same participants inserts a new row that violates the unique index on the deleted one, so the pair can never open a DM again (a DM with these members already exists). Two live DMs for one pair stay impossible.Migration notes (docs/database.md)
SET LOCAL lock_timeout = '5s'andstatement_timeout = '30s'.DROP INDEXandCREATE UNIQUE INDEXrun together under the table lock, sochannelsis never without a uniqueness guarantee for live DMs.channels, which is small in every deployment I know of. A deployment that applies migrations out of band can run the two statements in a maintenance window.Dependencies
Independent of #9792. It is based on current
mainand touches different files.Tests
Added
deleted_dm_does_not_block_reopening_the_same_pair(Postgres,#[ignore]like the neighbouring DM tests): open, delete, reopen creates a new DM, a third open reuses it. Local PostgreSQL 17, migrations applied withbuzz-admin migrate:cargo test -p buzz-db --lib deleted_dm_does_not_block -- --ignored: passes with the migration; fails without it (reopen dm after delete: InvalidData("a DM with these members already exists")).cargo test -p buzz-db --lib embedded_migrator_contains: ok.cargo test -p buzz-db --lib dm -- --include-ignored: 114 passed.cargo fmt -p buzz-db -- --check: ok.Not run locally: the rest of the workspace test suite,
buzz-relayintegration tests, andpgschemaagainstschema/.🤖 Generated with Claude Code