Repository navigation
Expand file tree
/
Copy path0022_notifications.sql
More file actions
51 lines (48 loc) · 2.38 KB
/
Copy path0022_notifications.sql
File metadata and controls
51 lines (48 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- Notifications: where to send them (ntfy, a webhook, email, Home
-- Assistant, Slack, Discord, Telegram, Pushover, Gotify) and which events. The token is left out of backups.
CREATE TABLE notification_channels (
id UUID PRIMARY KEY DEFAULT uuidv7(),
owner_id UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
kind TEXT NOT NULL
CONSTRAINT notification_channels_kind_ck
CHECK (kind IN ('ntfy', 'webhook', 'email', 'home_assistant', 'slack', 'discord', 'telegram', 'pushover', 'gotify')),
name TEXT NOT NULL CHECK (length(btrim(name)) > 0),
url TEXT,
token TEXT,
target TEXT,
on_low_stock BOOLEAN NOT NULL DEFAULT true,
on_print_pending BOOLEAN NOT NULL DEFAULT true,
on_drying_due BOOLEAN NOT NULL DEFAULT true,
enabled BOOLEAN NOT NULL DEFAULT true,
last_sent_at TIMESTAMPTZ,
last_error TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX notification_channels_owner_idx ON notification_channels (owner_id);
-- What has been told already, so each low spool or waiting print is told
-- once; the row goes when the condition does.
CREATE TABLE notification_state (
owner_id UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
event_key TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (owner_id, event_key)
);
-- A scale's NFC reader may only see the tag's serial number.
ALTER TABLE spools ADD COLUMN nfc_uid TEXT;
CREATE INDEX spools_nfc_uid_idx ON spools (owner_id, nfc_uid);
-- Server-wide: the mail server for email notifications, and the MQTT
-- broker Home Assistant listens on. Passwords stay out of backups.
ALTER TABLE app_settings
ADD COLUMN smtp_host TEXT,
ADD COLUMN smtp_port INTEGER,
ADD COLUMN smtp_security TEXT NOT NULL DEFAULT 'starttls'
CONSTRAINT app_settings_smtp_security_ck CHECK (smtp_security IN ('starttls', 'tls', 'none')),
ADD COLUMN smtp_username TEXT,
ADD COLUMN smtp_password TEXT,
ADD COLUMN smtp_from TEXT,
ADD COLUMN mqtt_enabled BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN mqtt_host TEXT,
ADD COLUMN mqtt_port INTEGER,
ADD COLUMN mqtt_username TEXT,
ADD COLUMN mqtt_password TEXT,
ADD COLUMN mqtt_prefix TEXT NOT NULL DEFAULT 'homeassistant';