mirror of
https://github.com/block/buzz.git
synced 2026-10-27 04:30:52 +00:00
21 lines
1.1 KiB
SQL
21 lines
1.1 KiB
SQL
-- ── Reactions ─────────────────────────────────────────────────────────────────
|
|
-- Conformance: reactions filter by community before event/pubkey matching.
|
|
|
|
CREATE TABLE reactions (
|
|
community_id UUID NOT NULL REFERENCES communities(id),
|
|
event_created_at TIMESTAMPTZ NOT NULL,
|
|
event_id BYTEA NOT NULL,
|
|
pubkey BYTEA NOT NULL,
|
|
emoji VARCHAR(66) NOT NULL,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
removed_at TIMESTAMPTZ,
|
|
reaction_event_id BYTEA,
|
|
PRIMARY KEY (community_id, event_created_at, event_id, pubkey, emoji)
|
|
);
|
|
|
|
CREATE INDEX idx_reactions_event ON reactions (community_id, event_id, event_created_at);
|
|
CREATE INDEX idx_reactions_pubkey ON reactions (community_id, pubkey);
|
|
-- A reaction's source event id is unique within a community.
|
|
CREATE UNIQUE INDEX idx_reactions_source_event ON reactions (community_id, reaction_event_id)
|
|
WHERE reaction_event_id IS NOT NULL;
|