| 1 | -- Email notifications: per-person settings, watching, thread subscriptions, |
| 2 | -- recognised sign-in devices and a log of every email sent. |
| 3 | |
| 4 | -- One row per person who changed a default. JSON, see src/mail/prefs.ts. |
| 5 | CREATE TABLE notification_prefs ( |
| 6 | account_id TEXT PRIMARY KEY REFERENCES accounts(id), |
| 7 | prefs TEXT NOT NULL, |
| 8 | updated_at TEXT NOT NULL |
| 9 | ); |
| 10 | |
| 11 | -- Watching a repository: 'all' (every issue, pull request and failed run), |
| 12 | -- 'participating' (the default: only threads you take part in) or 'ignore'. |
| 13 | CREATE TABLE repo_watches ( |
| 14 | account_id TEXT NOT NULL REFERENCES accounts(id), |
| 15 | repo_id TEXT NOT NULL REFERENCES repos(id) ON DELETE CASCADE, |
| 16 | level TEXT NOT NULL CHECK (level IN ('all', 'participating', 'ignore')), |
| 17 | updated_at TEXT NOT NULL, |
| 18 | PRIMARY KEY (account_id, repo_id) |
| 19 | ); |
| 20 | CREATE INDEX repo_watches_repo ON repo_watches(repo_id, level); |
| 21 | |
| 22 | -- Subscribe to (1) or mute (0) one issue or pull request. |
| 23 | CREATE TABLE thread_subscriptions ( |
| 24 | account_id TEXT NOT NULL REFERENCES accounts(id), |
| 25 | repo_id TEXT NOT NULL, |
| 26 | number INTEGER NOT NULL, |
| 27 | subscribed INTEGER NOT NULL, |
| 28 | updated_at TEXT NOT NULL, |
| 29 | PRIMARY KEY (account_id, repo_id, number) |
| 30 | ); |
| 31 | CREATE INDEX thread_subscriptions_thread ON thread_subscriptions(repo_id, number); |
| 32 | |
| 33 | -- Browsers and passkeys someone has signed in with, so only new ones raise an alert. |
| 34 | CREATE TABLE known_devices ( |
| 35 | account_id TEXT NOT NULL REFERENCES accounts(id), |
| 36 | fingerprint TEXT NOT NULL, |
| 37 | label TEXT NOT NULL, |
| 38 | first_seen TEXT NOT NULL, |
| 39 | last_seen TEXT NOT NULL, |
| 40 | PRIMARY KEY (account_id, fingerprint) |
| 41 | ); |
| 42 | |
| 43 | -- Every email Diffinery tried to send (whole messages are kept only in local development). |
| 44 | CREATE TABLE email_log ( |
| 45 | id TEXT PRIMARY KEY, |
| 46 | account_id TEXT, |
| 47 | to_addr TEXT NOT NULL, |
| 48 | kind TEXT NOT NULL, |
| 49 | subject TEXT NOT NULL, |
| 50 | status TEXT NOT NULL CHECK (status IN ('sent', 'failed', 'skipped')), |
| 51 | detail TEXT, |
| 52 | message_id TEXT, |
| 53 | dev_copy TEXT, -- the whole message, kept only in local development |
| 54 | created_at TEXT NOT NULL |
| 55 | ); |
| 56 | CREATE INDEX email_log_at ON email_log(created_at); |
| 57 | CREATE INDEX email_log_account ON email_log(account_id, created_at); |
| 58 | |
| 59 | -- Reminders sent once per token, a week before it expires. |
| 60 | ALTER TABLE tokens ADD COLUMN expiry_notified_at TEXT; |