tenseleyflow/shithub / 56eaf44

Browse files

Add migrations 0015-0016: user_notification_prefs (k/v jsonb) + users.theme + users.session_epoch

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
56eaf4402dcd04d4fe33abd54ba598fddb5e9c1b
Parents
f8fc2ba
Tree
1ba671b

2 changed files

StatusFile+-
A internal/migrationsfs/migrations/0015_user_notification_prefs.sql 27 0
A internal/migrationsfs/migrations/0016_users_settings_columns.sql 23 0
internal/migrationsfs/migrations/0015_user_notification_prefs.sqladded
@@ -0,0 +1,27 @@
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;
internal/migrationsfs/migrations/0016_users_settings_columns.sqladded
@@ -0,0 +1,23 @@
1
+-- SPDX-License-Identifier: AGPL-3.0-or-later
2
+--
3
+-- Account-settings columns:
4
+--
5
+-- - theme: persisted theme preference (cookie is the fast path, DB is
6
+--   the source of truth across devices). NULL → fall back to cookie/auto.
7
+-- - session_epoch: bumped by "log out everywhere" so existing cookies
8
+--   carrying a stale epoch fail validation on the next request.
9
+--
10
+-- The username-change rate-limit window is implicit in
11
+-- username_redirects.changed_at — we count rows in the last 60 days
12
+-- per user to enforce the 3/60d cap. No new column needed.
13
+
14
+-- +goose Up
15
+ALTER TABLE users
16
+    ADD COLUMN theme         text NOT NULL DEFAULT '',
17
+    ADD COLUMN session_epoch integer NOT NULL DEFAULT 0,
18
+    ADD CONSTRAINT users_theme_known CHECK (theme IN ('', 'light', 'dark', 'auto', 'high_contrast'));
19
+
20
+-- +goose Down
21
+ALTER TABLE users
22
+    DROP COLUMN IF EXISTS theme,
23
+    DROP COLUMN IF EXISTS session_epoch;