Changes:
- changed FOS DB structure
This commit is contained in:
parent
61401b06e1
commit
6b0f78a22d
1 changed files with 359 additions and 330 deletions
|
|
@ -1,13 +1,9 @@
|
|||
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
|
||||
|
|
@ -27,100 +23,102 @@ end;
|
|||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE TABLE tenants
|
||||
|
||||
CREATE TABLE public.tenants
|
||||
(
|
||||
tenant_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
name text,
|
||||
api_key text UNIQUE default generate_api_key(20) not null,
|
||||
tenant_id integer NOT NULL DEFAULT 1,
|
||||
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'),
|
||||
deleted_at timestamp without time zone NULL DEFAULT NULL,
|
||||
edition varchar(3) NOT NULL,
|
||||
version_number text NOT NULL,
|
||||
license text NULL,
|
||||
licence text NULL,
|
||||
opt_out bool NOT NULL DEFAULT FALSE,
|
||||
t_projects integer NOT NULL DEFAULT 1,
|
||||
t_sessions bigint NOT NULL DEFAULT 0,
|
||||
t_users integer NOT NULL DEFAULT 1,
|
||||
t_integrations integer NOT NULL DEFAULT 0
|
||||
t_integrations integer NOT NULL DEFAULT 0,
|
||||
CONSTRAINT onerow_uni CHECK (tenant_id = 1)
|
||||
);
|
||||
|
||||
CREATE TYPE user_role AS ENUM ('owner', 'admin', 'member');
|
||||
|
||||
CREATE TABLE users
|
||||
(
|
||||
user_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
tenant_id integer NOT NULL REFERENCES tenants (tenant_id) ON DELETE CASCADE,
|
||||
email text NOT NULL UNIQUE,
|
||||
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'),
|
||||
deleted_at timestamp without time zone NULL DEFAULT NULL,
|
||||
appearance jsonb NOT NULL default '{
|
||||
user_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
email text NOT NULL UNIQUE,
|
||||
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'),
|
||||
deleted_at timestamp without time zone NULL DEFAULT NULL,
|
||||
appearance jsonb NOT NULL default '{
|
||||
"role": "dev",
|
||||
"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,
|
||||
"cpu": false,
|
||||
"fps": false,
|
||||
"impactedSessionsByJsErrors": true,
|
||||
"impactedSessionsBySlowPages": true,
|
||||
"memoryConsumption": true,
|
||||
"missingResources": true,
|
||||
"avgCpu": false,
|
||||
"avgFps": false,
|
||||
"errors": true,
|
||||
"crashes": false,
|
||||
"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
|
||||
"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
|
||||
},
|
||||
"runs": false,
|
||||
"tests": false,
|
||||
"pagesDomBuildtime": 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,
|
||||
weekly_report boolean NOT NULL DEFAULT TRUE
|
||||
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,
|
||||
weekly_report boolean NOT NULL DEFAULT TRUE
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE basic_authentication
|
||||
(
|
||||
user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,
|
||||
|
|
@ -130,9 +128,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 TABLE oauth_authentication
|
||||
(
|
||||
|
|
@ -144,30 +142,28 @@ CREATE TABLE oauth_authentication
|
|||
);
|
||||
|
||||
|
||||
-- --- 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),
|
||||
tenant_id integer NOT NULL REFERENCES tenants (tenant_id) ON DELETE CASCADE,
|
||||
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,
|
||||
|
|
@ -175,8 +171,6 @@ CREATE TABLE projects
|
|||
}'::jsonb -- ??????
|
||||
);
|
||||
|
||||
CREATE INDEX ON public.projects (project_key);
|
||||
|
||||
CREATE OR REPLACE FUNCTION notify_project() RETURNS trigger AS
|
||||
$$
|
||||
BEGIN
|
||||
|
|
@ -191,82 +185,9 @@ 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;
|
||||
tenant_id integer;
|
||||
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;
|
||||
SELECT projects.tenant_id INTO tenant_id FROM public.projects WHERE projects.project_id = NEW.project_id LIMIT 1;
|
||||
clone = jsonb_set(clone, '{tenant_id}', to_jsonb(tenant_id));
|
||||
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,
|
||||
tenant_id integer not null
|
||||
constraint webhooks_tenant_id_fkey
|
||||
references tenants
|
||||
on delete cascade,
|
||||
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,
|
||||
tenant_id integer REFERENCES tenants (tenant_id) ON DELETE CASCADE,
|
||||
user_id integer REFERENCES users (user_id) ON DELETE CASCADE,
|
||||
title text NOT NULL,
|
||||
description text NOT NULL,
|
||||
|
|
@ -274,14 +195,12 @@ CREATE TABLE notifications
|
|||
button_url text NULL,
|
||||
image_url text NULL,
|
||||
created_at timestamp NOT NULL DEFAULT timezone('utc'::text, now()),
|
||||
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 )
|
||||
options jsonb NOT NULL DEFAULT '{}'::jsonb
|
||||
);
|
||||
CREATE INDEX notifications_user_id_index ON public.notifications (user_id);
|
||||
CREATE INDEX notifications_tenant_id_index ON public.notifications (tenant_id);
|
||||
CREATE INDEX notifications_created_at_index ON public.notifications (created_at DESC);
|
||||
CREATE INDEX notifications_created_at_epoch_idx ON public.notifications (CAST(EXTRACT(EPOCH FROM created_at) * 1000 AS BIGINT) DESC);
|
||||
|
||||
CREATE INDEX notifications_user_id_index ON notifications (user_id);
|
||||
CREATE INDEX notifications_created_at_index ON notifications (created_at DESC);
|
||||
CREATE INDEX notifications_created_at_epoch_idx ON notifications (CAST(EXTRACT(EPOCH FROM created_at) * 1000 AS BIGINT) DESC);
|
||||
|
||||
CREATE TABLE user_viewed_notifications
|
||||
(
|
||||
|
|
@ -290,23 +209,6 @@ CREATE TABLE user_viewed_notifications
|
|||
constraint user_viewed_notifications_pkey primary key (user_id, notification_id)
|
||||
);
|
||||
|
||||
-- --- funnels.sql ---
|
||||
|
||||
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');
|
||||
|
||||
|
|
@ -324,7 +226,92 @@ create table announcements
|
|||
type announcement_type default 'notification'::announcement_type not null
|
||||
);
|
||||
|
||||
-- --- integrations.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,
|
||||
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
|
||||
source error_source NOT NULL,
|
||||
name text DEFAULT NULL,
|
||||
message text NOT NULL,
|
||||
payload jsonb NOT NULL,
|
||||
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
|
||||
);
|
||||
CREATE INDEX ON errors (project_id, source);
|
||||
CREATE INDEX errors_message_gin_idx ON public.errors USING GIN (message gin_trgm_ops);
|
||||
CREATE INDEX errors_name_gin_idx ON public.errors USING GIN (name gin_trgm_ops);
|
||||
CREATE INDEX errors_project_id_idx ON public.errors (project_id);
|
||||
CREATE INDEX errors_project_id_status_idx ON public.errors (project_id, status);
|
||||
|
||||
CREATE TABLE user_favorite_errors
|
||||
(
|
||||
user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,
|
||||
error_id text NOT NULL REFERENCES errors (error_id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (user_id, error_id)
|
||||
);
|
||||
|
||||
CREATE TABLE user_viewed_errors
|
||||
(
|
||||
user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,
|
||||
error_id text NOT NULL REFERENCES errors (error_id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (user_id, error_id)
|
||||
);
|
||||
CREATE INDEX user_viewed_errors_user_id_idx ON public.user_viewed_errors (user_id);
|
||||
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'
|
||||
);
|
||||
|
||||
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
|
||||
|
|
@ -368,83 +355,73 @@ create table jira_cloud
|
|||
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
|
||||
CREATE TABLE funnels
|
||||
(
|
||||
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,
|
||||
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
|
||||
source error_source NOT NULL,
|
||||
name text DEFAULT NULL,
|
||||
message text NOT NULL,
|
||||
payload jsonb NOT NULL,
|
||||
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
|
||||
);
|
||||
CREATE INDEX ON errors (project_id, source);
|
||||
CREATE INDEX errors_message_gin_idx ON public.errors USING GIN (message gin_trgm_ops);
|
||||
CREATE INDEX errors_name_gin_idx ON public.errors USING GIN (name gin_trgm_ops);
|
||||
CREATE INDEX errors_project_id_idx ON public.errors (project_id);
|
||||
CREATE INDEX errors_project_id_status_idx ON public.errors (project_id, status);
|
||||
|
||||
CREATE TABLE user_favorite_errors
|
||||
(
|
||||
user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,
|
||||
error_id text NOT NULL REFERENCES errors (error_id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (user_id, error_id)
|
||||
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 TABLE user_viewed_errors
|
||||
CREATE INDEX ON public.funnels (user_id, is_public);
|
||||
|
||||
CREATE TYPE alert_detection_method AS ENUM ('threshold', 'change');
|
||||
|
||||
CREATE TABLE alerts
|
||||
(
|
||||
user_id integer NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,
|
||||
error_id text NOT NULL REFERENCES errors (error_id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (user_id, error_id)
|
||||
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 INDEX user_viewed_errors_user_id_idx ON public.user_viewed_errors (user_id);
|
||||
CREATE INDEX user_viewed_errors_error_id_idx ON public.user_viewed_errors (error_id);
|
||||
|
||||
|
||||
-- --- sessions.sql ---
|
||||
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');
|
||||
|
|
@ -508,6 +485,7 @@ 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);
|
||||
|
||||
|
|
@ -558,62 +536,6 @@ CREATE TABLE user_favorite_sessions
|
|||
);
|
||||
|
||||
|
||||
-- --- 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;
|
||||
|
||||
CREATE TABLE events.pages
|
||||
|
|
@ -747,19 +669,126 @@ END;
|
|||
$$ LANGUAGE plpgsql IMMUTABLE;
|
||||
|
||||
|
||||
-- --- autocomplete.sql ---
|
||||
|
||||
CREATE TABLE autocomplete
|
||||
CREATE SCHEMA events_common;
|
||||
|
||||
CREATE TYPE events_common.custom_level AS ENUM ('info','error');
|
||||
|
||||
CREATE TABLE events_common.customs
|
||||
(
|
||||
value text NOT NULL,
|
||||
type text NOT NULL,
|
||||
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE
|
||||
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 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 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;
|
||||
|
||||
|
||||
COMMIT;
|
||||
Loading…
Add table
Reference in a new issue