Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* refactor(chalice): changed logging

* feat(DB): rollback scripts

* feat(DB): init&delta scripts
  • Loading branch information
tahayk authored Jan 26, 2024
1 parent 16af8ee commit d6c9f46
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 51 deletions.
14 changes: 9 additions & 5 deletions ee/api/chalicelib/core/unlock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import uuid
from os import environ

Expand All @@ -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()))
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 13 additions & 13 deletions ee/scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
);
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
26 changes: 13 additions & 13 deletions scripts/schema/db/init_dbs/postgresql/1.17.0/1.17.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions scripts/schema/db/init_dbs/postgresql/init_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions scripts/schema/db/rollback_dbs/postgresql/1.17.0/1.17.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d6c9f46

Please sign in to comment.