feat(DB): sessions_notes structure

This commit is contained in:
Taha Yassine Kraiem 2022-09-28 13:40:22 +02:00
parent 968d25e29e
commit 21632f8c46
4 changed files with 60 additions and 1 deletions

View file

@ -7,4 +7,19 @@ $$ LANGUAGE sql IMMUTABLE;
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT);
CREATE TABLE IF NOT EXISTS sessions_notes
(
note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
message text NOT NULL,
created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'),
user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL,
deleted_at timestamp without time zone NULL DEFAULT NULL,
tags text[] NOT NULL DEFAULT '{}',
session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE,
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
timestamp integer NOT NULL DEFAULT -1,
is_public boolean NOT NULL DEFAULT FALSE
);
COMMIT;

View file

@ -129,7 +129,8 @@ $$
('user_viewed_errors'),
('user_viewed_sessions'),
('users'),
('webhooks'))
('webhooks'),
('sessions_notes'))
select bool_and(exists(select *
from information_schema.tables t
where table_schema = 'public'
@ -857,6 +858,20 @@ $$
FOR EACH ROW
EXECUTE PROCEDURE notify_alert();
CREATE TABLE IF NOT EXISTS sessions_notes
(
note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
message text NOT NULL,
created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'),
user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL,
deleted_at timestamp without time zone NULL DEFAULT NULL,
tags text[] NOT NULL DEFAULT '{}',
session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE,
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
timestamp integer NOT NULL DEFAULT -1,
is_public boolean NOT NULL DEFAULT FALSE
);
RAISE NOTICE 'Created missing public schema tables';
END IF;
END;

View file

@ -7,4 +7,19 @@ $$ LANGUAGE sql IMMUTABLE;
ALTER TABLE IF EXISTS public.tenants
ADD COLUMN IF NOT EXISTS last_telemetry bigint NOT NULL DEFAULT CAST(EXTRACT(epoch FROM date_trunc('day', now())) * 1000 AS BIGINT);
CREATE TABLE IF NOT EXISTS sessions_notes
(
note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
message text NOT NULL,
created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'),
user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL,
deleted_at timestamp without time zone NULL DEFAULT NULL,
tags text[] NOT NULL DEFAULT '{}',
session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE,
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
timestamp integer NOT NULL DEFAULT -1,
is_public boolean NOT NULL DEFAULT FALSE
);
COMMIT;

View file

@ -1000,6 +1000,20 @@ $$
FOR EACH ROW
EXECUTE PROCEDURE notify_alert();
CREATE TABLE sessions_notes
(
note_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY,
message text NOT NULL,
created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'),
user_id integer NULL REFERENCES users (user_id) ON DELETE SET NULL,
deleted_at timestamp without time zone NULL DEFAULT NULL,
tags text[] NOT NULL DEFAULT '{}',
session_id bigint NOT NULL REFERENCES sessions (session_id) ON DELETE CASCADE,
project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE,
timestamp integer NOT NULL DEFAULT -1,
is_public boolean NOT NULL DEFAULT FALSE
);
raise notice 'DB created';
END IF;
END;