teecup/026_notifications.sql

24 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

-- In-app varslingssenter (FEATURE_BACKLOG.md "Varsler"-runden, 2026-07-25).
-- Eid av BRUKER (mottaker), ikke organisasjon -- INGEN RLS, samme
-- plain_connection()-mønster som personlig profil/HCP-historikk/venner
-- (ADR-033 Beslutning A / ADR-036 Beslutning A). `message` er en FERDIG
-- norsk tekst, snapshot-prinsipp (samme som author_display_name i
-- meldinger, ADR-025) -- unngår å måtte slå opp relaterte data på nytt ved
-- hver lesing, og overlever at den relaterte raden (f.eks. en venneforespørsel)
-- senere slettes.
CREATE TABLE notification (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES app_user(id) ON DELETE CASCADE,
type text NOT NULL CHECK (type IN ('friend', 'tournament', 'round', 'result')),
message text NOT NULL,
link_path text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now(),
read_at timestamptz
);
CREATE INDEX notification_user_created_idx ON notification (user_id, created_at DESC);
CREATE INDEX notification_user_unread_idx ON notification (user_id) WHERE read_at IS NULL;
GRANT SELECT, INSERT, UPDATE, DELETE ON notification TO teecup_app;