Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfe411c

Browse files
committed
Add notification preferences migrations
Signed-off-by: Danny Kopping <danny@coder.com>
1 parenta960e98 commitbfe411c

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

‎coderd/database/dump.sql

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DROPTABLE IF EXISTS notification_preferences;
2+
3+
ALTERTABLE notification_templates
4+
DROP COLUMN IF EXISTS method;
5+
6+
DROPTRIGGER IF EXISTS inhibit_enqueue_if_disabled_triggerON notification_messages;
7+
DROPFUNCTION IF EXISTS inhibit_enqueue_if_disabled;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
CREATETABLEnotification_preferences
2+
(
3+
user_id uuidREFERENCES usersON DELETE CASCADENOT NULL,
4+
notification_template_id uuidREFERENCES notification_templatesON DELETE CASCADENOT NULL,
5+
disabled boolNOT NULL DEFAULT FALSE,
6+
created_atTIMESTAMP WITH TIME ZONENOT NULL DEFAULTCURRENT_TIMESTAMP,
7+
updated_atTIMESTAMP WITH TIME ZONENOT NULL DEFAULTCURRENT_TIMESTAMP
8+
);
9+
10+
-- Ensure we cannot insert multiple entries for the same user/template combination
11+
ALTERTABLE notification_preferences
12+
ADDCONSTRAINT unique_user_notification_template UNIQUE (user_id, notification_template_id);
13+
14+
-- Allow per-template notification method (enterprise only)
15+
ALTERTABLE notification_templates
16+
ADD COLUMN method notification_method;
17+
COMMENT ON COLUMN notification_templates.method IS'NULL defers to the deployment-level method';
18+
19+
-- No equivalent in down migration because ENUM values cannot be deleted
20+
ALTERTYPE notification_message_status ADD VALUE IF NOT EXISTS'inhibited';
21+
22+
-- Function to prevent enqueuing notifications unnecessarily
23+
CREATE OR REPLACEFUNCTIONinhibit_enqueue_if_disabled()
24+
RETURNS TRIGGERAS
25+
$$
26+
BEGIN
27+
-- Fail the insertion if the user has disabled this notification
28+
IF EXISTS (SELECT1
29+
FROM notification_preferences
30+
WHERE disabled= TRUE
31+
AND user_id=NEW.user_id
32+
AND notification_template_id=NEW.notification_template_id) THEN
33+
RAISE EXCEPTION'cannot enqueue message: user has disabled this notification';
34+
END IF;
35+
36+
RETURN NEW;
37+
END;
38+
$$ LANGUAGE plpgsql;
39+
40+
-- Trigger to execute above function on insertion
41+
CREATETRIGGERinhibit_enqueue_if_disabled_trigger
42+
BEFORE INSERT
43+
ON notification_messages
44+
FOR EACH ROW
45+
EXECUTE FUNCTION inhibit_enqueue_if_disabled();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp