25 lines
1.2 KiB
SQL
25 lines
1.2 KiB
SQL
-- 0005_warehouse: the notification placeholder. Phase 4 writes the storage quota alert here; phase 9 builds the
|
|||
|
|
-- delivery (mail, the bell) on this table. Runs as ps_migrate; 0001's default privileges give ps_app SELECT,
|
||
|
|
-- INSERT, UPDATE, DELETE on it.
|
||
|
|
|
||
|
|
-- One row per alert. An alert is open until resolved_at is set. Acknowledging it does not resolve it: the
|
||
|
|
-- condition that raised it has to clear.
|
||
|
|
CREATE TABLE notification_events (
|
||
|
|
id bigserial PRIMARY KEY,
|
||
|
|
kind text NOT NULL,
|
||
|
|
severity text NOT NULL DEFAULT 'warning' CHECK (severity IN ('info', 'warning', 'critical')),
|
||
|
|
subject text,
|
||
|
|
detail jsonb NOT NULL DEFAULT '{}',
|
||
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||
|
|
resolved_at timestamptz,
|
||
|
|
acknowledged_at timestamptz,
|
||
|
|
acknowledged_by uuid REFERENCES users (id)
|
||
|
|
);
|
||
|
|
|
||
|
|
-- At most one open alert per kind and subject.
|
||
|
|
CREATE UNIQUE INDEX notification_events_open ON notification_events (kind, coalesce(subject, ''))
|
||
|
|
WHERE resolved_at IS NULL;
|
||
|
|
CREATE INDEX notification_events_created ON notification_events (created_at DESC);
|
||
|
|
|
||
|
|
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ps_app;
|