From 21632f8c466f3bc3917efbdd7df7134f249d275f Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Wed, 28 Sep 2022 13:40:22 +0200 Subject: [PATCH] feat(DB): sessions_notes structure --- .../helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql | 15 +++++++++++++++ .../helm/db/init_dbs/postgresql/init_schema.sql | 17 ++++++++++++++++- .../helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql | 15 +++++++++++++++ .../helm/db/init_dbs/postgresql/init_schema.sql | 14 ++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/ee/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql b/ee/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql index 4eb88bd9e..3586ff63a 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql @@ -7,4 +7,19 @@ $$ LANGUAGE sql IMMUTABLE; ALTER TABLE IF EXISTS public.tenants ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT); + +CREATE TABLE IF NOT EXISTS sessions_notes +( + note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + message text NOT NULL, + created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), + user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL, + tags text[] NOT NULL DEFAULT '{}', + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + timestamp integer NOT NULL DEFAULT -1, + is_public boolean NOT NULL DEFAULT FALSE +); + COMMIT; \ No newline at end of file diff --git a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql index 2be29136b..792003dab 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -129,7 +129,8 @@ $$ ('user_viewed_errors'), ('user_viewed_sessions'), ('users'), - ('webhooks')) + ('webhooks'), + ('sessions_notes')) select bool_and(exists(select * from information_schema.tables t where table_schema = 'public' @@ -857,6 +858,20 @@ $$ FOR EACH ROW EXECUTE PROCEDURE notify_alert(); + CREATE TABLE IF NOT EXISTS sessions_notes + ( + note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + message text NOT NULL, + created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), + user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL, + tags text[] NOT NULL DEFAULT '{}', + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + timestamp integer NOT NULL DEFAULT -1, + is_public boolean NOT NULL DEFAULT FALSE + ); + RAISE NOTICE 'Created missing public schema tables'; END IF; END; diff --git a/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql b/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql index 57deb548d..4ce5009a3 100644 --- a/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql +++ b/scripts/helm/db/init_dbs/postgresql/1.8.2/1.8.2.sql @@ -7,4 +7,19 @@ $$ LANGUAGE sql IMMUTABLE; ALTER TABLE IF EXISTS public.tenants ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT); + +CREATE TABLE IF NOT EXISTS sessions_notes +( + note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + message text NOT NULL, + created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), + user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL, + tags text[] NOT NULL DEFAULT '{}', + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + timestamp integer NOT NULL DEFAULT -1, + is_public boolean NOT NULL DEFAULT FALSE +); + COMMIT; \ No newline at end of file diff --git a/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/scripts/helm/db/init_dbs/postgresql/init_schema.sql index ad435348e..9e3a0f924 100644 --- a/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -1000,6 +1000,20 @@ $$ FOR EACH ROW EXECUTE PROCEDURE notify_alert(); + CREATE TABLE sessions_notes + ( + note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + message text NOT NULL, + created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), + user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL, + tags text[] NOT NULL DEFAULT '{}', + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + timestamp integer NOT NULL DEFAULT -1, + is_public boolean NOT NULL DEFAULT FALSE + ); + raise notice 'DB created'; END IF; END;