From d65d344b5ecd68fc99af767b150d213092b8d649 Mon Sep 17 00:00:00 2001 From: KRAIEM Taha Yassine Date: Wed, 19 May 2021 21:02:30 +0200 Subject: [PATCH] Change: - changed DB structure --- .../db/init_dbs/postgresql/init_schema.sql | 130 +-- .../db/init_dbs/postgresql/init_schema.sql | 746 +++++++++--------- 2 files changed, 425 insertions(+), 451 deletions(-) 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 9010cb07a..bc1caf3b2 100644 --- a/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -55,65 +55,66 @@ CREATE TABLE users created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), deleted_at timestamp without time zone NULL DEFAULT NULL, appearance jsonb NOT NULL default '{ - "dashboard": { - "applicationActivity": true, - "avgCpu": true, - "avgDomContentLoadStart": true, - "avgFirstContentfulPixel": false, - "avgFirstPaint": false, - "avgFps": false, - "avgImageLoadTime": true, - "avgPageLoadTime": true, - "avgPagesDomBuildtime": true, - "avgPagesResponseTime": false, - "avgRequestLoadTime": true, - "avgSessionDuration": false, - "avgTillFirstBit": false, - "avgTimeToInteractive": true, - "avgTimeToRender": true, - "avgUsedJsHeapSize": true, - "avgVisitedPages": false, - "busiestTimeOfDay": true, - "callsErrors_4xx": true, - "callsErrors_5xx": true, - "countSessions": true, - "cpu": true, - "crashes": true, - "errors": true, - "errorsPerDomains": true, - "errorsPerType": true, - "errorsTrend": true, - "fps": false, - "impactedSessionsByJsErrors": true, - "impactedSessionsBySlowPages": true, - "memoryConsumption": true, - "missingResources": true, - "overview": true, - "pageMetrics": true, - "pagesResponseTime": true, - "pagesResponseTimeDistribution": true, - "performance": true, - "resourceTypeVsResponseEnd": true, - "resourcesByParty": false, - "resourcesCountByType": true, - "resourcesLoadingTime": true, - "resourcesVsVisuallyComplete": true, - "sessions": true, - "sessionsFeedback": false, - "sessionsFrustration": false, - "sessionsPerBrowser": false, - "slowestDomains": true, - "slowestImages": true, - "slowestResources": true, - "speedLocation": true, - "timeToRender": false, - "topMetrics": true, - "userActivity": false - }, - "runs": false, - "tests": false, - "pagesDomBuildtime": false - }'::jsonb, + "role": "dev", + "dashboard": { + "cpu": false, + "fps": false, + "avgCpu": false, + "avgFps": false, + "errors": true, + "crashes": false, + "overview": true, + "sessions": true, + "topMetrics": true, + "callsErrors": false, + "pageMetrics": true, + "performance": true, + "timeToRender": false, + "userActivity": false, + "avgFirstPaint": false, + "countSessions": false, + "errorsPerType": false, + "slowestImages": true, + "speedLocation": false, + "slowestDomains": false, + "avgPageLoadTime": false, + "avgTillFirstBit": false, + "avgTimeToRender": false, + "avgVisitedPages": false, + "avgImageLoadTime": false, + "busiestTimeOfDay": true, + "errorsPerDomains": false, + "missingResources": false, + "resourcesByParty": false, + "sessionsFeedback": false, + "slowestResources": false, + "avgUsedJsHeapSize": false, + "domainsErrors_4xx": false, + "domainsErrors_5xx": false, + "memoryConsumption": false, + "pagesDomBuildtime": false, + "pagesResponseTime": false, + "avgRequestLoadTime": false, + "avgSessionDuration": false, + "sessionsPerBrowser": false, + "applicationActivity": true, + "sessionsFrustration": false, + "avgPagesDomBuildtime": false, + "avgPagesResponseTime": false, + "avgTimeToInteractive": false, + "resourcesCountByType": false, + "resourcesLoadingTime": false, + "avgDomContentLoadStart": false, + "avgFirstContentfulPixel": false, + "resourceTypeVsResponseEnd": false, + "impactedSessionsByJsErrors": false, + "impactedSessionsBySlowPages": false, + "resourcesVsVisuallyComplete": false, + "pagesResponseTimeDistribution": false + }, + "sessionsLive": false, + "sessionsDevtools": true +}'::jsonb, api_key text UNIQUE default generate_api_key(20) not null, jwt_iat timestamp without time zone NULL DEFAULT NULL, data jsonb NOT NULL DEFAULT '{}'::jsonb, @@ -557,6 +558,17 @@ CREATE TABLE user_favorite_sessions PRIMARY KEY (user_id, session_id) ); +-- --- assignments.sql --- + +create table assigned_sessions +( + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + issue_id text NOT NULL, + provider oauth_provider NOT NULL, + created_by integer NOT NULL, + created_at timestamp default timezone('utc'::text, now()) NOT NULL, + provider_data jsonb default '{}'::jsonb NOT NULL +); -- --- events_common.sql --- diff --git a/scripts/helm/db/init_dbs/postgresql/init_schema.sql b/scripts/helm/db/init_dbs/postgresql/init_schema.sql index ed1449309..f8f3378db 100644 --- a/scripts/helm/db/init_dbs/postgresql/init_schema.sql +++ b/scripts/helm/db/init_dbs/postgresql/init_schema.sql @@ -1,18 +1,19 @@ BEGIN; +-- --- public.sql --- CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS pgcrypto; - +-- --- accounts.sql --- CREATE OR REPLACE FUNCTION generate_api_key(length integer) RETURNS text AS $$ declare - chars text[] := '{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}'; - result text := ''; + chars text[] := ''{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}''; + result text := ''''; i integer := 0; begin if length < 0 then - raise exception 'Given length cannot be less than 0'; + raise exception ''Given length cannot be less than 0''; end if; for i in 1..length loop @@ -30,10 +31,10 @@ CREATE TABLE public.tenants user_id text NOT NULL DEFAULT generate_api_key(20), name text NOT NULL, api_key text NOT NULL DEFAULT generate_api_key(20), - created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone 'utc'), + created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone ''utc''), edition varchar(3) NOT NULL, version_number text NOT NULL, - licence text NULL, + license text NULL, opt_out bool NOT NULL DEFAULT FALSE, t_projects integer NOT NULL DEFAULT 1, t_sessions bigint NOT NULL DEFAULT 0, @@ -42,80 +43,80 @@ CREATE TABLE public.tenants CONSTRAINT onerow_uni CHECK (tenant_id = 1) ); -CREATE TYPE user_role AS ENUM ('owner', 'admin', 'member'); +CREATE TYPE user_role AS ENUM (''owner'', ''admin'', ''member''); CREATE TABLE users ( user_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, email text NOT NULL UNIQUE, - role user_role NOT NULL DEFAULT 'member', + role user_role NOT NULL DEFAULT ''member'', name text NOT NULL, - created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), + created_at timestamp without time zone NOT NULL default (now() at time zone ''utc''), deleted_at timestamp without time zone NULL DEFAULT NULL, - appearance jsonb NOT NULL default '{ - "role": "dev", - "dashboard": { - "cpu": false, - "fps": false, - "avgCpu": false, - "avgFps": false, - "errors": true, - "crashes": false, - "overview": true, - "sessions": true, - "topMetrics": true, - "callsErrors": false, - "pageMetrics": true, - "performance": true, - "timeToRender": false, - "userActivity": false, - "avgFirstPaint": false, - "countSessions": false, - "errorsPerType": false, - "slowestImages": true, - "speedLocation": false, - "slowestDomains": false, - "avgPageLoadTime": false, - "avgTillFirstBit": false, - "avgTimeToRender": false, - "avgVisitedPages": false, - "avgImageLoadTime": false, - "busiestTimeOfDay": true, - "errorsPerDomains": false, - "missingResources": false, - "resourcesByParty": false, - "sessionsFeedback": false, - "slowestResources": false, - "avgUsedJsHeapSize": false, - "domainsErrors_4xx": false, - "domainsErrors_5xx": false, - "memoryConsumption": false, - "pagesDomBuildtime": false, - "pagesResponseTime": false, - "avgRequestLoadTime": false, - "avgSessionDuration": false, - "sessionsPerBrowser": false, - "applicationActivity": true, - "sessionsFrustration": false, - "avgPagesDomBuildtime": false, - "avgPagesResponseTime": false, - "avgTimeToInteractive": false, - "resourcesCountByType": false, - "resourcesLoadingTime": false, - "avgDomContentLoadStart": false, - "avgFirstContentfulPixel": false, - "resourceTypeVsResponseEnd": false, - "impactedSessionsByJsErrors": false, - "impactedSessionsBySlowPages": false, - "resourcesVsVisuallyComplete": false, - "pagesResponseTimeDistribution": false - }, - "sessionsLive": false, - "sessionsDevtools": true - }'::jsonb, + appearance jsonb NOT NULL default ''{ + "role": "dev", + "dashboard": { + "cpu": false, + "fps": false, + "avgCpu": false, + "avgFps": false, + "errors": true, + "crashes": false, + "overview": true, + "sessions": true, + "topMetrics": true, + "callsErrors": false, + "pageMetrics": true, + "performance": true, + "timeToRender": false, + "userActivity": false, + "avgFirstPaint": false, + "countSessions": false, + "errorsPerType": false, + "slowestImages": true, + "speedLocation": false, + "slowestDomains": false, + "avgPageLoadTime": false, + "avgTillFirstBit": false, + "avgTimeToRender": false, + "avgVisitedPages": false, + "avgImageLoadTime": false, + "busiestTimeOfDay": true, + "errorsPerDomains": false, + "missingResources": false, + "resourcesByParty": false, + "sessionsFeedback": false, + "slowestResources": false, + "avgUsedJsHeapSize": false, + "domainsErrors_4xx": false, + "domainsErrors_5xx": false, + "memoryConsumption": false, + "pagesDomBuildtime": false, + "pagesResponseTime": false, + "avgRequestLoadTime": false, + "avgSessionDuration": false, + "sessionsPerBrowser": false, + "applicationActivity": true, + "sessionsFrustration": false, + "avgPagesDomBuildtime": false, + "avgPagesResponseTime": false, + "avgTimeToInteractive": false, + "resourcesCountByType": false, + "resourcesLoadingTime": false, + "avgDomContentLoadStart": false, + "avgFirstContentfulPixel": false, + "resourceTypeVsResponseEnd": false, + "impactedSessionsByJsErrors": false, + "impactedSessionsBySlowPages": false, + "resourcesVsVisuallyComplete": false, + "pagesResponseTimeDistribution": false + }, + "sessionsLive": false, + "sessionsDevtools": true +}''::jsonb, api_key text UNIQUE default generate_api_key(20) not null, jwt_iat timestamp without time zone NULL DEFAULT NULL, - data jsonb NOT NULL DEFAULT '{}'::jsonb, + data jsonb NOT NULL DEFAULT ''{}''::jsonb, weekly_report boolean NOT NULL DEFAULT TRUE ); @@ -128,10 +129,9 @@ CREATE TABLE basic_authentication token_requested_at timestamp without time zone NULL DEFAULT NULL, changed_at timestamp, UNIQUE (user_id) - -- CHECK ((token IS NULL and token_requested_at IS NULL) or (token IS NOT NULL and token_requested_at IS NOT NULL)) ); -CREATE TYPE oauth_provider AS ENUM ('jira', 'github'); +CREATE TYPE oauth_provider AS ENUM (''jira'', ''github''); CREATE TABLE oauth_authentication ( user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, @@ -141,40 +141,40 @@ CREATE TABLE oauth_authentication UNIQUE (provider, provider_user_id) ); - +-- --- projects.sql --- CREATE TABLE projects ( project_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, - project_key varchar(20) NOT NULL UNIQUE DEFAULT generate_api_key(20), + project_key varchar(20) NOT NULL UNIQUE DEFAULT generate_api_key(20), name text NOT NULL, active boolean NOT NULL, - sample_rate smallint NOT NULL DEFAULT 100 CHECK (sample_rate >= 0 AND sample_rate <= 100), - created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone 'utc'), - deleted_at timestamp without time zone NULL DEFAULT NULL, - max_session_duration integer NOT NULL DEFAULT 7200000, - metadata_1 text DEFAULT NULL, - metadata_2 text DEFAULT NULL, - metadata_3 text DEFAULT NULL, - metadata_4 text DEFAULT NULL, - metadata_5 text DEFAULT NULL, - metadata_6 text DEFAULT NULL, - metadata_7 text DEFAULT NULL, - metadata_8 text DEFAULT NULL, - metadata_9 text DEFAULT NULL, - metadata_10 text DEFAULT NULL, - gdpr jsonb NOT NULL DEFAULT '{ + sample_rate smallint NOT NULL DEFAULT 100 CHECK (sample_rate >= 0 AND sample_rate <= 100), + created_at timestamp without time zone NOT NULL DEFAULT (now() at time zone ''utc''), + deleted_at timestamp without time zone NULL DEFAULT NULL, + max_session_duration integer NOT NULL DEFAULT 7200000, + metadata_1 text DEFAULT NULL, + metadata_2 text DEFAULT NULL, + metadata_3 text DEFAULT NULL, + metadata_4 text DEFAULT NULL, + metadata_5 text DEFAULT NULL, + metadata_6 text DEFAULT NULL, + metadata_7 text DEFAULT NULL, + metadata_8 text DEFAULT NULL, + metadata_9 text DEFAULT NULL, + metadata_10 text DEFAULT NULL, + gdpr jsonb NOT NULL DEFAULT ''{ "maskEmails": true, "sampleRate": 33, "maskNumbers": false, "defaultInputMode": "plain" - }'::jsonb -- ?????? + }''::jsonb -- ?????? ); CREATE OR REPLACE FUNCTION notify_project() RETURNS trigger AS $$ BEGIN - PERFORM pg_notify('project', row_to_json(NEW)::text); + PERFORM pg_notify(''project'', row_to_json(NEW)::text); RETURN NEW; END; $$ LANGUAGE plpgsql; @@ -185,6 +185,70 @@ CREATE TRIGGER on_insert_or_update FOR EACH ROW EXECUTE PROCEDURE notify_project(); +-- --- alerts.sql --- + +CREATE TYPE alert_detection_method AS ENUM (''threshold'', ''change''); + +CREATE TABLE alerts +( + alert_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + name text NOT NULL, + description text NULL DEFAULT NULL, + active boolean NOT NULL DEFAULT TRUE, + detection_method alert_detection_method NOT NULL, + query jsonb NOT NULL, + deleted_at timestamp NULL DEFAULT NULL, + created_at timestamp NOT NULL DEFAULT timezone(''utc''::text, now()), + options jsonb NOT NULL DEFAULT ''{ + "renotifyInterval": 1440 + }''::jsonb +); + + +CREATE OR REPLACE FUNCTION notify_alert() RETURNS trigger AS +$$ +DECLARE + clone jsonb; +BEGIN + clone = to_jsonb(NEW); + clone = jsonb_set(clone, ''{created_at}'', to_jsonb(CAST(EXTRACT(epoch FROM NEW.created_at) * 1000 AS BIGINT))); + IF NEW.deleted_at NOTNULL THEN + clone = jsonb_set(clone, ''{deleted_at}'', to_jsonb(CAST(EXTRACT(epoch FROM NEW.deleted_at) * 1000 AS BIGINT))); + END IF; + PERFORM pg_notify(''alert'', clone::text); + RETURN NEW; +END ; +$$ LANGUAGE plpgsql; + + +CREATE TRIGGER on_insert_or_update_or_delete + AFTER INSERT OR UPDATE OR DELETE + ON alerts + FOR EACH ROW +EXECUTE PROCEDURE notify_alert(); + +-- --- webhooks.sql --- + +create type webhook_type as enum (''webhook'', ''slack'', ''email''); + +create table webhooks +( + webhook_id integer generated by default as identity + constraint webhooks_pkey + primary key, + endpoint text not null, + created_at timestamp default timezone(''utc''::text, now()) not null, + deleted_at timestamp, + auth_header text, + type webhook_type not null, + index integer default 0 not null, + name varchar(100) +); + + +-- --- notifications.sql --- + CREATE TABLE notifications ( notification_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, @@ -194,8 +258,8 @@ CREATE TABLE notifications button_text varchar(80) NULL, button_url text NULL, image_url text NULL, - created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()), - options jsonb NOT NULL DEFAULT '{}'::jsonb + created_at timestamp NOT NULL DEFAULT timezone(''utc''::text, now()), + options jsonb NOT NULL DEFAULT ''{}''::jsonb ); CREATE INDEX notifications_user_id_index ON notifications (user_id); @@ -209,8 +273,25 @@ CREATE TABLE user_viewed_notifications constraint user_viewed_notifications_pkey primary key (user_id, notification_id) ); +-- --- funnels.sql --- -create type announcement_type as enum ('notification', 'alert'); +CREATE TABLE funnels +( + funnel_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, + name text not null, + filter jsonb not null, + created_at timestamp default timezone(''utc''::text, now()) not null, + deleted_at timestamp, + is_public boolean NOT NULL DEFAULT False +); + +CREATE INDEX ON public.funnels (user_id, is_public); + +-- --- announcements.sql --- + +create type announcement_type as enum (''notification'', ''alert''); create table announcements ( @@ -222,12 +303,93 @@ create table announcements button_text varchar(30), button_url text, image_url text, - created_at timestamp default timezone('utc'::text, now()) not null, - type announcement_type default 'notification'::announcement_type not null + created_at timestamp default timezone(''utc''::text, now()) not null, + type announcement_type default ''notification''::announcement_type not null ); -CREATE TYPE error_source AS ENUM ('js_exception', 'bugsnag', 'cloudwatch', 'datadog', 'newrelic', 'rollbar', 'sentry', 'stackdriver', 'sumologic'); -CREATE TYPE error_status AS ENUM ('unresolved', 'resolved', 'ignored'); +-- --- integrations.sql --- + +CREATE TYPE integration_provider AS ENUM (''bugsnag'', ''cloudwatch'', ''datadog'', ''newrelic'', ''rollbar'', ''sentry'', ''stackdriver'', ''sumologic'', ''elasticsearch''); --, ''jira'', ''github''); +CREATE TABLE integrations +( + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + provider integration_provider NOT NULL, + options jsonb NOT NULL, + request_data jsonb NOT NULL DEFAULT ''{}''::jsonb, + PRIMARY KEY (project_id, provider) +); + +CREATE OR REPLACE FUNCTION notify_integration() RETURNS trigger AS +$$ +BEGIN + IF NEW IS NULL THEN + PERFORM pg_notify(''integration'', (row_to_json(OLD)::text || ''{"options": null, "request_data": null}''::text)); + ELSIF (OLD IS NULL) OR (OLD.options <> NEW.options) THEN + PERFORM pg_notify(''integration'', row_to_json(NEW)::text); + END IF; + RETURN NULL; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER on_insert_or_update_or_delete + AFTER INSERT OR UPDATE OR DELETE + ON integrations + FOR EACH ROW +EXECUTE PROCEDURE notify_integration(); + + +create table jira_cloud +( + user_id integer not null + constraint jira_cloud_pk + primary key + constraint jira_cloud_users_fkey + references users + on delete cascade, + username text not null, + token text not null, + url text +); + +-- --- issues.sql --- + +CREATE TYPE issue_type AS ENUM ( + ''click_rage'', + ''dead_click'', + ''excessive_scrolling'', + ''bad_request'', + ''missing_resource'', + ''memory'', + ''cpu'', + ''slow_resource'', + ''slow_page_load'', + ''crash'', + ''ml_cpu'', + ''ml_memory'', + ''ml_dead_click'', + ''ml_click_rage'', + ''ml_mouse_thrashing'', + ''ml_excessive_scrolling'', + ''ml_slow_resources'', + ''custom'', + ''js_exception'' + ); + +CREATE TABLE issues +( + issue_id text NOT NULL PRIMARY KEY, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, + type issue_type NOT NULL, + context_string text NOT NULL, + context jsonb DEFAULT NULL +); +CREATE INDEX ON issues (issue_id, type); +CREATE INDEX issues_context_string_gin_idx ON public.issues USING GIN (context_string gin_trgm_ops); + +-- --- errors.sql --- + +CREATE TYPE error_source AS ENUM (''js_exception'', ''bugsnag'', ''cloudwatch'', ''datadog'', ''newrelic'', ''rollbar'', ''sentry'', ''stackdriver'', ''sumologic''); +CREATE TYPE error_status AS ENUM (''unresolved'', ''resolved'', ''ignored''); CREATE TABLE errors ( error_id text NOT NULL PRIMARY KEY, @@ -236,7 +398,7 @@ CREATE TABLE errors name text DEFAULT NULL, message text NOT NULL, payload jsonb NOT NULL, - status error_status NOT NULL DEFAULT 'unresolved', + status error_status NOT NULL DEFAULT ''unresolved'', parent_error_id text DEFAULT NULL REFERENCES errors (error_id) ON DELETE SET NULL, stacktrace jsonb, --to save the stacktrace and not query S3 another time stacktrace_parsed_at timestamp @@ -264,168 +426,11 @@ CREATE INDEX user_viewed_errors_user_id_idx ON public.user_viewed_errors (user_i CREATE INDEX user_viewed_errors_error_id_idx ON public.user_viewed_errors (error_id); -CREATE TYPE issue_type AS ENUM ( - 'click_rage', - 'dead_click', - 'excessive_scrolling', - 'bad_request', - 'missing_resource', - 'memory', - 'cpu', - 'slow_resource', - 'slow_page_load', - 'crash', - 'ml_cpu', - 'ml_memory', - 'ml_dead_click', - 'ml_click_rage', - 'ml_mouse_thrashing', - 'ml_excessive_scrolling', - 'ml_slow_resources', - 'custom', - 'js_exception' - ); +-- --- sessions.sql --- -CREATE TABLE issues -( - issue_id text NOT NULL PRIMARY KEY, - project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, - type issue_type NOT NULL, - context_string text NOT NULL, - context jsonb DEFAULT NULL -); -CREATE INDEX ON issues (issue_id, type); -CREATE INDEX issues_context_string_gin_idx ON public.issues USING GIN (context_string gin_trgm_ops); - -create type webhook_type as enum ('webhook', 'slack', 'email'); - -create table webhooks -( - webhook_id integer generated by default as identity - constraint webhooks_pkey - primary key, - endpoint text not null, - created_at timestamp default timezone('utc'::text, now()) not null, - deleted_at timestamp, - auth_header text, - type webhook_type not null, - index integer default 0 not null, - name varchar(100) -); - -CREATE TYPE integration_provider AS ENUM ('bugsnag', 'cloudwatch', 'datadog', 'newrelic', 'rollbar', 'sentry', 'stackdriver', 'sumologic', 'elasticsearch'); --, 'jira', 'github'); -CREATE TABLE integrations -( - project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, - provider integration_provider NOT NULL, - options jsonb NOT NULL, - request_data jsonb NOT NULL DEFAULT '{}'::jsonb, - PRIMARY KEY (project_id, provider) -); - -CREATE OR REPLACE FUNCTION notify_integration() RETURNS trigger AS -$$ -BEGIN - IF NEW IS NULL THEN - PERFORM pg_notify('integration', (row_to_json(OLD)::text || '{"options": null, "request_data": null}'::text)); - ELSIF (OLD IS NULL) OR (OLD.options <> NEW.options) THEN - PERFORM pg_notify('integration', row_to_json(NEW)::text); - END IF; - RETURN NULL; -END; -$$ LANGUAGE plpgsql; - -CREATE TRIGGER on_insert_or_update_or_delete - AFTER INSERT OR UPDATE OR DELETE - ON integrations - FOR EACH ROW -EXECUTE PROCEDURE notify_integration(); - - -create table jira_cloud -( - user_id integer not null - constraint jira_cloud_pk - primary key - constraint jira_cloud_users_fkey - references users - on delete cascade, - username text not null, - token text not null, - url text -); - -CREATE TABLE funnels -( - funnel_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, - project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, - user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, - name text not null, - filter jsonb not null, - created_at timestamp default timezone('utc'::text, now()) not null, - deleted_at timestamp, - is_public boolean NOT NULL DEFAULT False -); - -CREATE INDEX ON public.funnels (user_id, is_public); - -CREATE TYPE alert_detection_method AS ENUM ('threshold', 'change'); - -CREATE TABLE alerts -( - alert_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, - project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, - name text NOT NULL, - description text NULL DEFAULT NULL, - active boolean NOT NULL DEFAULT TRUE, - detection_method alert_detection_method NOT NULL, - query jsonb NOT NULL, - deleted_at timestamp NULL DEFAULT NULL, - created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()), - options jsonb NOT NULL DEFAULT '{ - "renotifyInterval": 1440 - }'::jsonb -); - - -CREATE OR REPLACE FUNCTION notify_alert() RETURNS trigger AS -$$ -DECLARE - clone jsonb; -BEGIN - clone = to_jsonb(NEW); - clone = jsonb_set(clone, '{created_at}', to_jsonb(CAST(EXTRACT(epoch FROM NEW.created_at) * 1000 AS BIGINT))); - IF NEW.deleted_at NOTNULL THEN - clone = jsonb_set(clone, '{deleted_at}', to_jsonb(CAST(EXTRACT(epoch FROM NEW.deleted_at) * 1000 AS BIGINT))); - END IF; - PERFORM pg_notify('alert', clone::text); - RETURN NEW; -END ; -$$ LANGUAGE plpgsql; - - -CREATE TRIGGER on_insert_or_update_or_delete - AFTER INSERT OR UPDATE OR DELETE - ON alerts - FOR EACH ROW -EXECUTE PROCEDURE notify_alert(); - -CREATE TABLE autocomplete -( - value text NOT NULL, - type text NOT NULL, - project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE -); - -CREATE unique index autocomplete_unique ON autocomplete (project_id, value, type); -CREATE index autocomplete_project_id_idx ON autocomplete (project_id); -CREATE INDEX autocomplete_type_idx ON public.autocomplete (type); -CREATE INDEX autocomplete_value_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops); - - -CREATE TYPE device_type AS ENUM ('desktop', 'tablet', 'mobile', 'other'); -CREATE TYPE country AS ENUM ('UN', 'RW', 'SO', 'YE', 'IQ', 'SA', 'IR', 'CY', 'TZ', 'SY', 'AM', 'KE', 'CD', 'DJ', 'UG', 'CF', 'SC', 'JO', 'LB', 'KW', 'OM', 'QA', 'BH', 'AE', 'IL', 'TR', 'ET', 'ER', 'EG', 'SD', 'GR', 'BI', 'EE', 'LV', 'AZ', 'LT', 'SJ', 'GE', 'MD', 'BY', 'FI', 'AX', 'UA', 'MK', 'HU', 'BG', 'AL', 'PL', 'RO', 'XK', 'ZW', 'ZM', 'KM', 'MW', 'LS', 'BW', 'MU', 'SZ', 'RE', 'ZA', 'YT', 'MZ', 'MG', 'AF', 'PK', 'BD', 'TM', 'TJ', 'LK', 'BT', 'IN', 'MV', 'IO', 'NP', 'MM', 'UZ', 'KZ', 'KG', 'TF', 'HM', 'CC', 'PW', 'VN', 'TH', 'ID', 'LA', 'TW', 'PH', 'MY', 'CN', 'HK', 'BN', 'MO', 'KH', 'KR', 'JP', 'KP', 'SG', 'CK', 'TL', 'RU', 'MN', 'AU', 'CX', 'MH', 'FM', 'PG', 'SB', 'TV', 'NR', 'VU', 'NC', 'NF', 'NZ', 'FJ', 'LY', 'CM', 'SN', 'CG', 'PT', 'LR', 'CI', 'GH', 'GQ', 'NG', 'BF', 'TG', 'GW', 'MR', 'BJ', 'GA', 'SL', 'ST', 'GI', 'GM', 'GN', 'TD', 'NE', 'ML', 'EH', 'TN', 'ES', 'MA', 'MT', 'DZ', 'FO', 'DK', 'IS', 'GB', 'CH', 'SE', 'NL', 'AT', 'BE', 'DE', 'LU', 'IE', 'MC', 'FR', 'AD', 'LI', 'JE', 'IM', 'GG', 'SK', 'CZ', 'NO', 'VA', 'SM', 'IT', 'SI', 'ME', 'HR', 'BA', 'AO', 'NA', 'SH', 'BV', 'BB', 'CV', 'GY', 'GF', 'SR', 'PM', 'GL', 'PY', 'UY', 'BR', 'FK', 'GS', 'JM', 'DO', 'CU', 'MQ', 'BS', 'BM', 'AI', 'TT', 'KN', 'DM', 'AG', 'LC', 'TC', 'AW', 'VG', 'VC', 'MS', 'MF', 'BL', 'GP', 'GD', 'KY', 'BZ', 'SV', 'GT', 'HN', 'NI', 'CR', 'VE', 'EC', 'CO', 'PA', 'HT', 'AR', 'CL', 'BO', 'PE', 'MX', 'PF', 'PN', 'KI', 'TK', 'TO', 'WF', 'WS', 'NU', 'MP', 'GU', 'PR', 'VI', 'UM', 'AS', 'CA', 'US', 'PS', 'RS', 'AQ', 'SX', 'CW', 'BQ', 'SS'); -CREATE TYPE platform AS ENUM ('web','ios','android'); +CREATE TYPE device_type AS ENUM (''desktop'', ''tablet'', ''mobile'', ''other''); +CREATE TYPE country AS ENUM (''UN'', ''RW'', ''SO'', ''YE'', ''IQ'', ''SA'', ''IR'', ''CY'', ''TZ'', ''SY'', ''AM'', ''KE'', ''CD'', ''DJ'', ''UG'', ''CF'', ''SC'', ''JO'', ''LB'', ''KW'', ''OM'', ''QA'', ''BH'', ''AE'', ''IL'', ''TR'', ''ET'', ''ER'', ''EG'', ''SD'', ''GR'', ''BI'', ''EE'', ''LV'', ''AZ'', ''LT'', ''SJ'', ''GE'', ''MD'', ''BY'', ''FI'', ''AX'', ''UA'', ''MK'', ''HU'', ''BG'', ''AL'', ''PL'', ''RO'', ''XK'', ''ZW'', ''ZM'', ''KM'', ''MW'', ''LS'', ''BW'', ''MU'', ''SZ'', ''RE'', ''ZA'', ''YT'', ''MZ'', ''MG'', ''AF'', ''PK'', ''BD'', ''TM'', ''TJ'', ''LK'', ''BT'', ''IN'', ''MV'', ''IO'', ''NP'', ''MM'', ''UZ'', ''KZ'', ''KG'', ''TF'', ''HM'', ''CC'', ''PW'', ''VN'', ''TH'', ''ID'', ''LA'', ''TW'', ''PH'', ''MY'', ''CN'', ''HK'', ''BN'', ''MO'', ''KH'', ''KR'', ''JP'', ''KP'', ''SG'', ''CK'', ''TL'', ''RU'', ''MN'', ''AU'', ''CX'', ''MH'', ''FM'', ''PG'', ''SB'', ''TV'', ''NR'', ''VU'', ''NC'', ''NF'', ''NZ'', ''FJ'', ''LY'', ''CM'', ''SN'', ''CG'', ''PT'', ''LR'', ''CI'', ''GH'', ''GQ'', ''NG'', ''BF'', ''TG'', ''GW'', ''MR'', ''BJ'', ''GA'', ''SL'', ''ST'', ''GI'', ''GM'', ''GN'', ''TD'', ''NE'', ''ML'', ''EH'', ''TN'', ''ES'', ''MA'', ''MT'', ''DZ'', ''FO'', ''DK'', ''IS'', ''GB'', ''CH'', ''SE'', ''NL'', ''AT'', ''BE'', ''DE'', ''LU'', ''IE'', ''MC'', ''FR'', ''AD'', ''LI'', ''JE'', ''IM'', ''GG'', ''SK'', ''CZ'', ''NO'', ''VA'', ''SM'', ''IT'', ''SI'', ''ME'', ''HR'', ''BA'', ''AO'', ''NA'', ''SH'', ''BV'', ''BB'', ''CV'', ''GY'', ''GF'', ''SR'', ''PM'', ''GL'', ''PY'', ''UY'', ''BR'', ''FK'', ''GS'', ''JM'', ''DO'', ''CU'', ''MQ'', ''BS'', ''BM'', ''AI'', ''TT'', ''KN'', ''DM'', ''AG'', ''LC'', ''TC'', ''AW'', ''VG'', ''VC'', ''MS'', ''MF'', ''BL'', ''GP'', ''GD'', ''KY'', ''BZ'', ''SV'', ''GT'', ''HN'', ''NI'', ''CR'', ''VE'', ''EC'', ''CO'', ''PA'', ''HT'', ''AR'', ''CL'', ''BO'', ''PE'', ''MX'', ''PF'', ''PN'', ''KI'', ''TK'', ''TO'', ''WF'', ''WS'', ''NU'', ''MP'', ''GU'', ''PR'', ''VI'', ''UM'', ''AS'', ''CA'', ''US'', ''PS'', ''RS'', ''AQ'', ''SX'', ''CW'', ''BQ'', ''SS''); +CREATE TYPE platform AS ENUM (''web'',''ios'',''android''); CREATE TABLE sessions ( @@ -433,9 +438,9 @@ CREATE TABLE sessions project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, tracker_version text NOT NULL, start_ts bigint NOT NULL, - duration integer DEFAULT NULL, + duration integer NOT NULL, rev_id text DEFAULT NULL, - platform platform NOT NULL DEFAULT 'web', + platform platform NOT NULL DEFAULT ''web'', is_snippet boolean NOT NULL DEFAULT FALSE, user_id text DEFAULT NULL, user_anonymous_id text DEFAULT NULL, @@ -455,7 +460,7 @@ CREATE TABLE sessions errors_count integer NOT NULL DEFAULT 0, watchdogs_score bigint NOT NULL DEFAULT 0, issue_score bigint NOT NULL DEFAULT 0, - issue_types issue_type[] NOT NULL DEFAULT '{}'::issue_type[], + issue_types issue_type[] NOT NULL DEFAULT ''{}''::issue_type[], metadata_1 text DEFAULT NULL, metadata_2 text DEFAULT NULL, metadata_3 text DEFAULT NULL, @@ -466,8 +471,6 @@ CREATE TABLE sessions metadata_8 text DEFAULT NULL, metadata_9 text DEFAULT NULL, metadata_10 text DEFAULT NULL --- , --- rehydration_id integer REFERENCES rehydrations(rehydration_id) ON DELETE SET NULL ); CREATE INDEX ON sessions (project_id, start_ts); CREATE INDEX ON sessions (project_id, user_id); @@ -485,7 +488,6 @@ CREATE INDEX ON sessions (project_id, metadata_7); CREATE INDEX ON sessions (project_id, metadata_8); CREATE INDEX ON sessions (project_id, metadata_9); CREATE INDEX ON sessions (project_id, metadata_10); --- CREATE INDEX ON sessions (rehydration_id); CREATE INDEX ON sessions (project_id, watchdogs_score DESC); CREATE INDEX platform_idx ON public.sessions (platform); @@ -507,17 +509,19 @@ CREATE INDEX sessions_user_anonymous_id_gin_idx ON public.sessions USING GIN (us CREATE INDEX sessions_user_country_gin_idx ON public.sessions (project_id, user_country); CREATE INDEX ON sessions (project_id, user_country); CREATE INDEX ON sessions (project_id, user_browser); +CREATE INDEX sessions_start_ts_idx ON public.sessions (start_ts) WHERE duration > 0; +CREATE INDEX sessions_project_id_idx ON public.sessions (project_id) WHERE duration > 0; ALTER TABLE public.sessions - ADD CONSTRAINT web_browser_constraint CHECK ( (sessions.platform = 'web' AND sessions.user_browser NOTNULL) OR - (sessions.platform != 'web' AND sessions.user_browser ISNULL)); + ADD CONSTRAINT web_browser_constraint CHECK ( (sessions.platform = ''web'' AND sessions.user_browser NOTNULL) OR + (sessions.platform != ''web'' AND sessions.user_browser ISNULL)); ALTER TABLE public.sessions - ADD CONSTRAINT web_user_browser_version_constraint CHECK ( sessions.platform = 'web' OR sessions.user_browser_version ISNULL); + ADD CONSTRAINT web_user_browser_version_constraint CHECK ( sessions.platform = ''web'' OR sessions.user_browser_version ISNULL); ALTER TABLE public.sessions - ADD CONSTRAINT web_user_agent_constraint CHECK ( (sessions.platform = 'web' AND sessions.user_agent NOTNULL) OR - (sessions.platform != 'web' AND sessions.user_agent ISNULL)); + ADD CONSTRAINT web_user_agent_constraint CHECK ( (sessions.platform = ''web'' AND sessions.user_agent NOTNULL) OR + (sessions.platform != ''web'' AND sessions.user_agent ISNULL)); @@ -535,6 +539,73 @@ CREATE TABLE user_favorite_sessions PRIMARY KEY (user_id, session_id) ); +-- --- assignments.sql --- + +create table assigned_sessions +( + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + issue_id text NOT NULL, + provider oauth_provider NOT NULL, + created_by integer NOT NULL, + created_at timestamp default timezone(''utc''::text, now()) NOT NULL, + provider_data jsonb default ''{}''::jsonb NOT NULL +); + +-- --- events_common.sql --- + +CREATE SCHEMA events_common; + +CREATE TYPE events_common.custom_level AS ENUM (''info'',''error''); + +CREATE TABLE events_common.customs +( + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + timestamp bigint NOT NULL, + seq_index integer NOT NULL, + name text NOT NULL, + payload jsonb NOT NULL, + level events_common.custom_level NOT NULL DEFAULT ''info'', + PRIMARY KEY (session_id, timestamp, seq_index) +); +CREATE INDEX ON events_common.customs (name); +CREATE INDEX customs_name_gin_idx ON events_common.customs USING GIN (name gin_trgm_ops); +CREATE INDEX ON events_common.customs (timestamp); + + +CREATE TABLE events_common.issues +( + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + timestamp bigint NOT NULL, + seq_index integer NOT NULL, + issue_id text NOT NULL REFERENCES issues (issue_id) ON DELETE CASCADE, + payload jsonb DEFAULT NULL, + PRIMARY KEY (session_id, timestamp, seq_index) +); + + +CREATE TABLE events_common.requests +( + session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, + timestamp bigint NOT NULL, + seq_index integer NOT NULL, + url text NOT NULL, + duration integer NOT NULL, + success boolean NOT NULL, + PRIMARY KEY (session_id, timestamp, seq_index) +); +CREATE INDEX ON events_common.requests (url); +CREATE INDEX ON events_common.requests (duration); +CREATE INDEX requests_url_gin_idx ON events_common.requests USING GIN (url gin_trgm_ops); +CREATE INDEX ON events_common.requests (timestamp); +CREATE INDEX requests_url_gin_idx2 ON events_common.requests USING GIN (RIGHT(url, length(url) - (CASE + WHEN url LIKE ''http://%'' + THEN 7 + WHEN url LIKE ''https://%'' + THEN 8 + ELSE 0 END)) + gin_trgm_ops); + +-- --- events.sql --- CREATE SCHEMA events; @@ -569,9 +640,9 @@ CREATE INDEX pages_base_path_idx ON events.pages (base_path); CREATE INDEX pages_base_path_idx2 ON events.pages (RIGHT(base_path, length(base_path) - 1)); CREATE INDEX pages_base_referrer_idx ON events.pages (base_referrer); CREATE INDEX pages_base_referrer_gin_idx2 ON events.pages USING GIN (RIGHT(base_referrer, length(base_referrer) - (CASE - WHEN base_referrer LIKE 'http://%' + WHEN base_referrer LIKE ''http://%'' THEN 7 - WHEN base_referrer LIKE 'https://%' + WHEN base_referrer LIKE ''https://%'' THEN 8 ELSE 0 END)) gin_trgm_ops); @@ -668,127 +739,18 @@ BEGIN END; $$ LANGUAGE plpgsql IMMUTABLE; +-- --- autocomplete.sql --- - -CREATE SCHEMA events_common; - -CREATE TYPE events_common.custom_level AS ENUM ('info','error'); - -CREATE TABLE events_common.customs +CREATE TABLE autocomplete ( - session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, - timestamp bigint NOT NULL, - seq_index integer NOT NULL, - name text NOT NULL, - payload jsonb NOT NULL, - level events_common.custom_level NOT NULL DEFAULT 'info', - PRIMARY KEY (session_id, timestamp, seq_index) -); -CREATE INDEX ON events_common.customs (name); -CREATE INDEX customs_name_gin_idx ON events_common.customs USING GIN (name gin_trgm_ops); -CREATE INDEX ON events_common.customs (timestamp); - - -CREATE TABLE events_common.issues -( - session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, - timestamp bigint NOT NULL, - seq_index integer NOT NULL, - issue_id text NOT NULL REFERENCES issues (issue_id) ON DELETE CASCADE, - payload jsonb DEFAULT NULL, - PRIMARY KEY (session_id, timestamp, seq_index) + value text NOT NULL, + type text NOT NULL, + project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE ); - -CREATE TABLE events_common.requests -( - session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, - timestamp bigint NOT NULL, - seq_index integer NOT NULL, - url text NOT NULL, - duration integer NOT NULL, - success boolean NOT NULL, - PRIMARY KEY (session_id, timestamp, seq_index) -); -CREATE INDEX ON events_common.requests (url); -CREATE INDEX ON events_common.requests (duration); -CREATE INDEX requests_url_gin_idx ON events_common.requests USING GIN (url gin_trgm_ops); -CREATE INDEX ON events_common.requests (timestamp); -CREATE INDEX requests_url_gin_idx2 ON events_common.requests USING GIN (RIGHT(url, length(url) - (CASE - WHEN url LIKE 'http://%' - THEN 7 - WHEN url LIKE 'https://%' - THEN 8 - ELSE 0 END)) - gin_trgm_ops); - -CREATE TYPE events.resource_type AS ENUM ('other', 'script', 'stylesheet', 'fetch', 'img', 'media'); -CREATE TYPE events.resource_method AS ENUM ('GET' , 'HEAD' , 'POST' , 'PUT' , 'DELETE' , 'CONNECT' , 'OPTIONS' , 'TRACE' , 'PATCH' ); -CREATE TABLE events.resources -( - session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, - message_id bigint NOT NULL, - timestamp bigint NOT NULL, - duration bigint NULL, - type events.resource_type NOT NULL, - url text NOT NULL, - url_host text NOT NULL, - url_hostpath text NOT NULL, - success boolean NOT NULL, - status smallint NULL, - method events.resource_method NULL, - ttfb bigint NULL, - header_size bigint NULL, - encoded_body_size integer NULL, - decoded_body_size integer NULL, - PRIMARY KEY (session_id, message_id) -); -CREATE INDEX ON events.resources (session_id); -CREATE INDEX ON events.resources (timestamp); -CREATE INDEX ON events.resources (success); -CREATE INDEX ON events.resources (status); -CREATE INDEX ON events.resources (type); -CREATE INDEX ON events.resources (duration) WHERE duration > 0; -CREATE INDEX ON events.resources (url_host); - -CREATE INDEX resources_url_gin_idx ON events.resources USING GIN (url gin_trgm_ops); -CREATE INDEX resources_url_idx ON events.resources (url); -CREATE INDEX resources_url_hostpath_gin_idx ON events.resources USING GIN (url_hostpath gin_trgm_ops); -CREATE INDEX resources_url_hostpath_idx ON events.resources (url_hostpath); - - - -CREATE TABLE events.performance -( - session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE, - timestamp bigint NOT NULL, - message_id bigint NOT NULL, - min_fps smallint NOT NULL, - avg_fps smallint NOT NULL, - max_fps smallint NOT NULL, - min_cpu smallint NOT NULL, - avg_cpu smallint NOT NULL, - max_cpu smallint NOT NULL, - min_total_js_heap_size bigint NOT NULL, - avg_total_js_heap_size bigint NOT NULL, - max_total_js_heap_size bigint NOT NULL, - min_used_js_heap_size bigint NOT NULL, - avg_used_js_heap_size bigint NOT NULL, - max_used_js_heap_size bigint NOT NULL, - PRIMARY KEY (session_id, message_id) -); - - -ALTER TABLE events.pages - ADD COLUMN ttfb integer DEFAULT NULL; -CREATE INDEX pages_path_gin_idx ON events.pages USING GIN (path gin_trgm_ops); -CREATE INDEX pages_path_idx ON events.pages (path); -CREATE INDEX pages_visually_complete_idx ON events.pages (visually_complete) WHERE visually_complete > 0; -CREATE INDEX pages_dom_building_time_idx ON events.pages (dom_building_time) WHERE dom_building_time > 0; -CREATE INDEX pages_load_time_idx ON events.pages (load_time) WHERE load_time > 0; - -CREATE INDEX sessions_start_ts_idx ON public.sessions (start_ts) WHERE duration > 0; -CREATE INDEX sessions_project_id_idx ON public.sessions (project_id) WHERE duration > 0; - +CREATE unique index autocomplete_unique ON autocomplete (project_id, value, type); +CREATE index autocomplete_project_id_idx ON autocomplete (project_id); +CREATE INDEX autocomplete_type_idx ON public.autocomplete (type); +CREATE INDEX autocomplete_value_gin_idx ON public.autocomplete USING GIN (value gin_trgm_ops); COMMIT; \ No newline at end of file