mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
Reverts #9650 (squash commit `eebf62b6`), except for migration `0097` and the channel artifact sync fences it added. Community scope adds a relay access gate based on community admission rather than channel membership, a new relay-admin command kind (`9034`) and an operator-run key transition. Its design and NIP-AR text need relay maintainer review before they ship. Two integration gaps also remain: - Media download authorization looks up references only in `events`, so an attachment referenced only by a community artifact is unreadable when media-read enforcement is on. - User erasure retires a community head in the database without signaling live syncs, so members who are already syncing keep the erased copy. The feature can return as a new PR once those are resolved. ## Kept from #9650 - **Migration `0097`, byte for byte.** Published images already include it, and databases that auto-migrated have recorded it. Dropping it would stop those relays from starting. It only adds columns and indexes that the channel code ignores. The declared schema matches that expanded shape and keeps the `(community_id, artifact_id)` primary key, so the operator key transition no longer exists. - **Channel artifact sync fences.** Snapshot and live sends check for a pending resync and for connection cancellation under the queue lock. A reader who loses access, or whose content is redacted, while a frame is in flight therefore receives no further payload. Handler-backed tests cover a resync recorded while a snapshot payload waits for queue room and one recorded after a live head read. ## Compatibility This revert supports databases that applied only migration `0097`, which is all that auto-migration runs. A database that ran #9650's operator contract script, or was bootstrapped from #9650's declared schema, has no `(community_id, artifact_id)` key, so channel artifact writes fail there. Before deploying to such a database, check that `artifact_heads_pkey` is on `(community_id, artifact_id)` and that `artifact_heads` has no rows with `scope = 'community'`; if either check fails, it needs a separate recovery step. --------- Signed-off-by: Will Pfleger <wpfleger@block.xyz> Co-authored-by: Paul <4a1bfa0013bc6d14a8d600d8bf6392efefbd2a26ac3c96c9b2a106b0d12297ca@buzz.block.builderlab.xyz>
26 lines
1.2 KiB
SQL
26 lines
1.2 KiB
SQL
-- NIP-AR current heads and acceptance ledger are independent of event retention.
|
|
CREATE TABLE artifact_heads (
|
|
community_id UUID NOT NULL REFERENCES communities(id),
|
|
artifact_id UUID NOT NULL,
|
|
scope TEXT NOT NULL DEFAULT 'channel',
|
|
event_id BYTEA NOT NULL CHECK (length(event_id) = 32),
|
|
channel_id UUID,
|
|
artifact_type TEXT NOT NULL,
|
|
root BYTEA,
|
|
deleted BOOLEAN NOT NULL DEFAULT false,
|
|
modified_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
PRIMARY KEY (community_id, artifact_id)
|
|
);
|
|
CREATE UNIQUE INDEX artifact_heads_scoped_identity
|
|
ON artifact_heads (community_id, scope, artifact_id);
|
|
CREATE INDEX artifact_heads_event ON artifact_heads (community_id, event_id);
|
|
CREATE INDEX artifact_heads_modified ON artifact_heads (community_id, modified_at, artifact_id);
|
|
CREATE INDEX artifact_heads_channel ON artifact_heads (community_id, channel_id, artifact_id);
|
|
|
|
-- The relay does not expire events. Any future row retention or partition
|
|
-- retirement must skip payloads referenced by `artifact_heads.event_id`
|
|
-- (NIP-AR: expiring earlier revisions MUST NOT remove the current revision).
|
|
|
|
CREATE INDEX artifact_heads_live_type
|
|
ON artifact_heads (community_id, scope, artifact_type, artifact_id) WHERE NOT deleted;
|