feat(DB): changed alerts structure to support UI
This commit is contained in:
parent
32c7e00c74
commit
9107389945
4 changed files with 48 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue