From 11f4cfbb89304cc96b3ced9ba8310a6808cf4204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Costa?= Date: Tue, 28 Nov 2023 13:38:43 +0100 Subject: [PATCH] feat(desktop-notifications): add new table for session management This feature introduces a new session table which is needed by the `icinga-notifications-web` project. It stores the current authenticated sessions into the table which allows the background daemon (php-based) to validate a connection and its corresponding browser to an authenticated session. Read #118 for more information about this addition. --- schema/pgsql/schema.sql | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index 90d2f197..a26a7a50 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -277,3 +277,32 @@ CREATE TABLE incident_history ( CONSTRAINT pk_incident_history PRIMARY KEY (id), FOREIGN KEY (incident_id, rule_escalation_id) REFERENCES incident_rule_escalation_state(incident_id, rule_escalation_id) ); + +CREATE OR REPLACE FUNCTION now_extended() RETURNS bigint + LANGUAGE SQL AS +$$ +SELECT ((EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1_000) :: bigint); +$$; + +CREATE TABLE session +( + id VARCHAR(256) NOT NULL, + username VARCHAR(254) NOT NULL, + device_id VARCHAR(8) NOT NULL, + authenticated_at bigint NOT NULL DEFAULT now_extended(), + + CONSTRAINT pk_id_username_device PRIMARY KEY (id, username, device_id) +); + +CREATE INDEX idx_id ON session ( + id + ); + +CREATE INDEX idx_authenticated ON session ( + authenticated_at + ); + +CREATE INDEX idx_username_device ON session ( + username, + device_id + );