Add user notification inbox and delivery controls

This commit is contained in:
JB
2026-07-25 15:29:21 -04:00
parent ff7f3a6d34
commit 29f4de807a
24 changed files with 606 additions and 18 deletions
+24
View File
@@ -25,6 +25,30 @@ CREATE TABLE IF NOT EXISTS avatar_reviews (
reviewed_by TEXT REFERENCES users(id),
review_note TEXT
);
CREATE TABLE IF NOT EXISTS notifications (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
category TEXT NOT NULL CHECK(category IN ('isac', 'contributions', 'comments', 'builds', 'guides', 'system')),
source TEXT NOT NULL,
title TEXT NOT NULL,
body TEXT NOT NULL,
link TEXT,
mandatory INTEGER NOT NULL DEFAULT 0 CHECK(mandatory IN (0, 1)),
created_at TEXT NOT NULL,
read_at TEXT,
emailed_at TEXT
);
CREATE INDEX IF NOT EXISTS notifications_user_created_idx ON notifications(user_id, created_at DESC);
CREATE INDEX IF NOT EXISTS notifications_user_unread_idx ON notifications(user_id, read_at, created_at DESC);
CREATE TABLE IF NOT EXISTS notification_preferences (
user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
category TEXT NOT NULL CHECK(category IN ('isac', 'contributions', 'comments', 'builds', 'guides', 'system')),
in_app_enabled INTEGER NOT NULL DEFAULT 1 CHECK(in_app_enabled IN (0, 1)),
browser_enabled INTEGER NOT NULL DEFAULT 0 CHECK(browser_enabled IN (0, 1)),
email_frequency TEXT NOT NULL DEFAULT 'none' CHECK(email_frequency IN ('none', 'immediate', 'daily')),
updated_at TEXT NOT NULL,
PRIMARY KEY(user_id, category)
);
CREATE INDEX IF NOT EXISTS avatar_reviews_status_submitted_idx ON avatar_reviews(status, submitted_at DESC);
CREATE INDEX IF NOT EXISTS avatar_reviews_user_submitted_idx ON avatar_reviews(user_id, submitted_at DESC);
CREATE TABLE IF NOT EXISTS builds (id TEXT PRIMARY KEY, owner_id TEXT NOT NULL REFERENCES users(id), title TEXT NOT NULL, slug TEXT NOT NULL UNIQUE, visibility TEXT NOT NULL DEFAULT 'draft', summary TEXT, guide_body TEXT, source_build_id TEXT REFERENCES builds(id), created_at TEXT NOT NULL, updated_at TEXT NOT NULL);