From d6c9f466e56df2c0f87eb5f1791b040a2e7d5871 Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Fri, 26 Jan 2024 18:03:00 +0100 Subject: [PATCH] Dev (#1860) * refactor(chalice): changed logging * feat(DB): rollback scripts * feat(DB): init&delta scripts --- ee/api/chalicelib/core/unlock.py | 14 ++++++---- .../clickhouse/create/init_schema.sql | 2 +- .../db/init_dbs/postgresql/1.17.0/1.17.0.sql | 26 +++++++++---------- .../db/init_dbs/postgresql/init_schema.sql | 18 ++++++------- .../rollback_dbs/postgresql/1.17.0/1.17.0.sql | 3 +++ .../db/init_dbs/postgresql/1.17.0/1.17.0.sql | 26 +++++++++---------- .../db/init_dbs/postgresql/init_schema.sql | 20 +++++++------- .../rollback_dbs/postgresql/1.17.0/1.17.0.sql | 3 +++ 8 files changed, 61 insertions(+), 51 deletions(-) diff --git a/ee/api/chalicelib/core/unlock.py b/ee/api/chalicelib/core/unlock.py index cb38446a3f..deb7c5f798 100644 --- a/ee/api/chalicelib/core/unlock.py +++ b/ee/api/chalicelib/core/unlock.py @@ -1,3 +1,4 @@ +import logging import uuid from os import environ @@ -7,6 +8,8 @@ from chalicelib.utils import helper from chalicelib.utils.TimeUTC import TimeUTC +logger = logging.getLogger(__name__) + def __get_mid(): return str(uuid.UUID(int=uuid.getnode())) @@ -19,15 +22,16 @@ def get_license(): def check(): license = get_license() if license is None or len(license) == 0: - print("!! license key not found, please provide a LICENSE_KEY env var") + logger.warning("!! license key not found, please provide a LICENSE_KEY env var") environ["expiration"] = "-1" environ["numberOfSeats"] = "0" return - print(f"validating: {helper.obfuscate(license)}") - r = requests.post('https://api.openreplay.com/license/validate', json={"mid": __get_mid(), "license": get_license()}) + logger.info(f"validating: {helper.obfuscate(license)}") + r = requests.post('https://api.openreplay.com/license/validate', + json={"mid": __get_mid(), "license": get_license()}) if r.status_code != 200 or "errors" in r.json() or not r.json()["data"].get("valid"): - print("license validation failed") - print(r.text) + logger.warning("license validation failed") + logger.warning(r.text) environ["expiration"] = "-1" else: environ["expiration"] = str(r.json()["data"].get("expiration")) diff --git a/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql b/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql index c746579bb4..0d406b36d3 100644 --- a/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql @@ -1,4 +1,4 @@ -CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.16.0-ee'; +CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.17.0-ee'; CREATE DATABASE IF NOT EXISTS experimental; CREATE TABLE IF NOT EXISTS experimental.autocomplete diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql index 039ce83d11..761b1a578e 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql @@ -43,23 +43,23 @@ CREATE TABLE IF NOT EXISTS public.projects_conditions CREATE TABLE IF NOT EXISTS public.tags ( - tag_id serial NOT NULL PRIMARY KEY, - name text NOT NULL, - project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, - selector text NOT NULL, - ignore_click_rage boolean NOT NULL, - ignore_dead_click boolean NOT NULL, - deleted_at timestamp without time zone NULL DEFAULT NULL + tag_id serial NOT NULL PRIMARY KEY, + name text NOT NULL, + project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, + selector text NOT NULL, + ignore_click_rage boolean NOT NULL, + ignore_dead_click boolean NOT NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL ); -CREATE INDEX tags_project_id_idx ON public.tags (project_id); +CREATE INDEX IF NOT EXISTS tags_project_id_idx ON public.tags (project_id); CREATE TABLE IF NOT EXISTS events.tags ( - session_id bigint NOT NULL REFERENCES public.sessions (session_id) ON DELETE CASCADE, - timestamp bigint NOT NULL, - seq_index integer NOT NULL, - tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, - PRIMARY KEY (session_id, timestamp, seq_index) + session_id bigint NOT NULL REFERENCES public.sessions (session_id) ON DELETE CASCADE, + timestamp bigint NOT NULL, + seq_index integer NOT NULL, + tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, + PRIMARY KEY (session_id, timestamp, seq_index) ); CREATE INDEX IF NOT EXISTS tags_session_id_idx ON events.tags (session_id); CREATE INDEX IF NOT EXISTS tags_timestamp_idx ON events.tags (timestamp); diff --git a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 3931679682..03f6835ada 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -291,7 +291,7 @@ $$ button_url text NULL, image_url text NULL, created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()), - options jsonb NOT NULL DEFAULT'{}'::jsonb, + options jsonb NOT NULL DEFAULT '{}'::jsonb, CONSTRAINT notification_tenant_xor_user CHECK ( tenant_id NOTNULL AND user_id ISNULL OR tenant_id ISNULL AND user_id NOTNULL ) ); @@ -1172,13 +1172,13 @@ $$ CREATE TABLE public.tags ( - tag_id serial NOT NULL PRIMARY KEY, - name text NOT NULL, - project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, - selector text NOT NULL, - ignore_click_rage boolean NOT NULL, - ignore_dead_click boolean NOT NULL, - deleted_at timestamp without time zone NULL DEFAULT NULL + tag_id serial NOT NULL PRIMARY KEY, + name text NOT NULL, + project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, + selector text NOT NULL, + ignore_click_rage boolean NOT NULL, + ignore_dead_click boolean NOT NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL ); CREATE INDEX tags_project_id_idx ON public.tags (project_id); @@ -1187,7 +1187,7 @@ $$ session_id bigint NOT NULL REFERENCES public.sessions (session_id) ON DELETE CASCADE, timestamp bigint NOT NULL, seq_index integer NOT NULL, - tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, + tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, PRIMARY KEY (session_id, timestamp, seq_index) ); CREATE INDEX tags_session_id_idx ON events.tags (session_id); diff --git a/ee/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql b/ee/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql index 7ff97c6910..8fbffce732 100644 --- a/ee/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql +++ b/ee/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql @@ -19,6 +19,9 @@ $fn_def$, :'next_version') -- +DROP TABLE IF EXISTS public.projects_conditions; +DROP TABLE IF EXISTS events.tags; +DROP TABLE IF EXISTS public.tags; COMMIT; diff --git a/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql b/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql index e3bdd73501..8924283e0e 100644 --- a/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql +++ b/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql @@ -43,23 +43,23 @@ CREATE TABLE IF NOT EXISTS public.projects_conditions CREATE TABLE IF NOT EXISTS public.tags ( - tag_id serial NOT NULL PRIMARY KEY, - name text NOT NULL, - project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, - selector text NOT NULL, - ignore_click_rage boolean NOT NULL, - ignore_dead_click boolean NOT NULL, - deleted_at timestamp without time zone NULL DEFAULT NULL + tag_id serial NOT NULL PRIMARY KEY, + name text NOT NULL, + project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, + selector text NOT NULL, + ignore_click_rage boolean NOT NULL, + ignore_dead_click boolean NOT NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL ); -CREATE INDEX tags_project_id_idx ON public.tags (project_id); +CREATE INDEX IF NOT EXISTS tags_project_id_idx ON public.tags (project_id); CREATE TABLE IF NOT EXISTS events.tags ( - session_id bigint NOT NULL REFERENCES public.sessions (session_id) ON DELETE CASCADE, - timestamp bigint NOT NULL, - seq_index integer NOT NULL, - tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, - PRIMARY KEY (session_id, timestamp, seq_index) + session_id bigint NOT NULL REFERENCES public.sessions (session_id) ON DELETE CASCADE, + timestamp bigint NOT NULL, + seq_index integer NOT NULL, + tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, + PRIMARY KEY (session_id, timestamp, seq_index) ); CREATE INDEX IF NOT EXISTS tags_session_id_idx ON events.tags (session_id); CREATE INDEX IF NOT EXISTS tags_timestamp_idx ON events.tags (timestamp); diff --git a/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 0032d8f8f7..444b9bbc21 100644 --- a/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -1130,16 +1130,16 @@ $$ CREATE INDEX swipes_label_gin_idx ON events_ios.swipes USING GIN (label gin_trgm_ops); CREATE INDEX swipes_timestamp_idx ON events_ios.swipes (timestamp); CREATE INDEX swipes_label_session_id_timestamp_idx ON events_ios.swipes (label, session_id, timestamp); - + CREATE TABLE public.tags ( - tag_id serial NOT NULL PRIMARY KEY, - name text NOT NULL, - project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, - selector text NOT NULL, - ignore_click_rage boolean NOT NULL, - ignore_dead_click boolean NOT NULL, - deleted_at timestamp without time zone NULL DEFAULT NULL + tag_id serial NOT NULL PRIMARY KEY, + name text NOT NULL, + project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, + selector text NOT NULL, + ignore_click_rage boolean NOT NULL, + ignore_dead_click boolean NOT NULL, + deleted_at timestamp without time zone NULL DEFAULT NULL ); CREATE INDEX tags_project_id_idx ON public.tags (project_id); @@ -1148,7 +1148,7 @@ $$ session_id bigint NOT NULL REFERENCES public.sessions (session_id) ON DELETE CASCADE, timestamp bigint NOT NULL, seq_index integer NOT NULL, - tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, + tag_id integer NOT NULL REFERENCES public.tags (tag_id) ON DELETE CASCADE, PRIMARY KEY (session_id, timestamp, seq_index) ); CREATE INDEX tags_session_id_idx ON events.tags (session_id); @@ -1218,7 +1218,7 @@ $$ ); CREATE INDEX canvas_recordings_session_id_idx ON events.canvas_recordings (session_id); - CREATE TABLE IF NOT EXISTS public.projects_conditions + CREATE TABLE public.projects_conditions ( condition_id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, project_id integer NOT NULL REFERENCES public.projects (project_id) ON DELETE CASCADE, diff --git a/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql b/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql index ef3ffb734d..6f53a8460e 100644 --- a/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql +++ b/scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql @@ -20,6 +20,9 @@ $fn_def$, :'next_version') -- +DROP TABLE IF EXISTS public.projects_conditions; +DROP TABLE IF EXISTS events.tags; +DROP TABLE IF EXISTS public.tags; COMMIT;