| 1 | -- SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | -- |
| 3 | -- Notification preferences as generic key/value rows. Schema is |
| 4 | -- intentionally light: a per-user (key, value) pair where value is JSONB |
| 5 | -- so future preferences (per-repo overrides, per-frequency settings, |
| 6 | -- digest schedules) don't need migrations. |
| 7 | -- |
| 8 | -- Examples: |
| 9 | -- ('issues_email', 'true'::jsonb) |
| 10 | -- ('mentions_email', 'true'::jsonb) |
| 11 | -- ('pr_review_requests_email','true'::jsonb) |
| 12 | -- ('email_frequency', '"per_event"'::jsonb) |
| 13 | |
| 14 | -- +goose Up |
| 15 | CREATE TABLE user_notification_prefs ( |
| 16 | user_id bigint NOT NULL REFERENCES users(id) ON DELETE CASCADE, |
| 17 | key text NOT NULL, |
| 18 | value jsonb NOT NULL, |
| 19 | updated_at timestamptz NOT NULL DEFAULT now(), |
| 20 | PRIMARY KEY (user_id, key) |
| 21 | ); |
| 22 | |
| 23 | CREATE TRIGGER set_updated_at BEFORE UPDATE ON user_notification_prefs |
| 24 | FOR EACH ROW EXECUTE FUNCTION tg_set_updated_at(); |
| 25 | |
| 26 | -- +goose Down |
| 27 | DROP TABLE IF EXISTS user_notification_prefs; |
| 28 |