OXYGENHUB
◆ v0.3.0 oxygenhub / crates / hub / migrations / 0013_notification_threads.sql
1.0 KiB · SQL · last changed Notifications by thread: participating versus watching, filters by kind and repository, read, unread and done per thread, and opening a row marks it read 1 month ago source blame history raw
eb0c44a9 Andy McCall ↶ 1
-- Notifications grouped by thread, filtered by repository, split into
2
-- participating and watching, and set aside when done (hub spec §10).
3
4
ALTER TABLE notifications ADD COLUMN repo_id INTEGER REFERENCES repositories(id) ON DELETE CASCADE;
5
-- The page the notification is about, without a fragment: one row per thread in the inbox.
6
ALTER TABLE notifications ADD COLUMN thread TEXT NOT NULL DEFAULT '';
7
ALTER TABLE notifications ADD COLUMN reason TEXT NOT NULL DEFAULT 'participating' CHECK (reason IN ('participating', 'watching'));
8
ALTER TABLE notifications ADD COLUMN done INTEGER NOT NULL DEFAULT 0;
9
10
UPDATE notifications SET thread = CASE WHEN instr(url, '#') > 0 THEN substr(url, 1, instr(url, '#') - 1) ELSE url END;
11
UPDATE notifications SET repo_id = (
12
    SELECT r.id FROM repositories r
13
    WHERE substr(notifications.url, 1, length('/' || r.owner || '/' || r.name || '/')) = '/' || r.owner || '/' || r.name || '/'
14
);
15
CREATE INDEX notifications_by_thread ON notifications (account_id, done, thread, at_ms DESC);