From 910738994526e643ad4cb0e36bda04114daea228 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Fri, 26 Aug 2022 18:59:56 +0100 Subject: [PATCH] feat(DB): changed alerts structure to support UI --- .../db/init_dbs/postgresql/1.8.0/1.8.0.sql | 19 +++++++++++++++++++ .../db/init_dbs/postgresql/init_schema.sql | 8 ++++++++ .../db/init_dbs/postgresql/1.8.0/1.8.0.sql | 19 +++++++++++++++++++ .../db/init_dbs/postgresql/init_schema.sql | 2 ++ 4 files changed, 48 insertions(+) diff --git a/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql b/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql index 90c4322bc..0decabdce 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql @@ -9,6 +9,25 @@ ALTER TABLE IF EXISTS projects ADD COLUMN IF NOT EXISTS first_recorded_session_at timestamp without time zone NULL DEFAULT NULL, ADD COLUMN IF NOT EXISTS sessions_last_check_at timestamp without time zone NULL DEFAULT NULL; + +DO +$$ + BEGIN + IF NOT EXISTS(SELECT * + FROM pg_type typ + INNER JOIN pg_namespace nsp + ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'alert_change_type') THEN + CREATE TYPE alert_change_type AS ENUM ('percent', 'change'); + END IF; + END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE IF EXISTS alerts + ADD COLUMN IF NOT EXISTS change alert_change_type NOT NULL DEFAULT 'change'; + COMMIT; CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_unique_project_id_md5value_type_idx ON autocomplete (project_id, md5(value), type); 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 dd5c380da..4a4e7b716 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -819,6 +819,13 @@ $$ WHERE typ.typname = 'alert_detection_method') THEN CREATE TYPE alert_detection_method AS ENUM ('threshold', 'change'); END IF; + + IF NOT EXISTS(SELECT * + FROM pg_type typ + WHERE typ.typname = 'alert_detection_method') THEN + CREATE TYPE alert_change_type AS ENUM ('percent', 'change'); + END IF; + CREATE TABLE IF NOT EXISTS alerts ( alert_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, @@ -828,6 +835,7 @@ $$ description text NULL DEFAULT NULL, active boolean NOT NULL DEFAULT TRUE, detection_method alert_detection_method NOT NULL, + change alert_change_type NOT NULL DEFAULT 'change', query jsonb NOT NULL, deleted_at timestamp NULL DEFAULT NULL, created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()), diff --git a/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql b/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql index bfe903ee5..64aa33581 100644 --- a/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql +++ b/scripts/helm/db/init_dbs/postgresql/1.8.0/1.8.0.sql @@ -9,6 +9,25 @@ ALTER TABLE IF EXISTS projects ADD COLUMN IF NOT EXISTS first_recorded_session_at timestamp without time zone NULL DEFAULT NULL, ADD COLUMN IF NOT EXISTS sessions_last_check_at timestamp without time zone NULL DEFAULT NULL; + +DO +$$ + BEGIN + IF NOT EXISTS(SELECT * + FROM pg_type typ + INNER JOIN pg_namespace nsp + ON nsp.oid = typ.typnamespace + WHERE nsp.nspname = current_schema() + AND typ.typname = 'alert_change_type') THEN + CREATE TYPE alert_change_type AS ENUM ('percent', 'change'); + END IF; + END; +$$ +LANGUAGE plpgsql; + +ALTER TABLE IF EXISTS alerts + ADD COLUMN IF NOT EXISTS change alert_change_type NOT NULL DEFAULT 'change'; + COMMIT; CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS autocomplete_unique_project_id_md5value_type_idx ON autocomplete (project_id, md5(value), type); diff --git a/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/scripts/helm/db/init_dbs/postgresql/init_schema.sql index d8fe2afcb..6b0340757 100644 --- a/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -967,6 +967,7 @@ $$ CREATE INDEX searches_project_id_idx ON public.searches (project_id); CREATE TYPE alert_detection_method AS ENUM ('threshold', 'change'); + CREATE TYPE alert_change_type AS ENUM ('percent', 'change'); CREATE TABLE alerts ( @@ -977,6 +978,7 @@ $$ description text NULL DEFAULT NULL, active boolean NOT NULL DEFAULT TRUE, detection_method alert_detection_method NOT NULL, + change alert_change_type NOT NULL DEFAULT 'change', query jsonb NOT NULL, deleted_at timestamp NULL DEFAULT NULL, created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()),