From 42332677b21caffe2c1c46a05c132b8a2a275ce0 Mon Sep 17 00:00:00 2001 From: Mateo Date: Thu, 16 May 2024 08:57:45 +0200 Subject: [PATCH 1/2] summerized all migration files --- .../migrations/sql/10_add_lock_board.down.sql | 1 - .../migrations/sql/10_add_lock_board.up.sql | 1 - .../sql/11_remove_note_assignments.down.sql | 7 - .../sql/11_remove_note_assignments.up.sql | 1 - .../sql/12_add_banned_column.down.sql | 1 - .../sql/12_add_banned_column.up.sql | 1 - .../sql/13_increase_gauth_avatar_url.down.sql | 8 - .../sql/13_increase_gauth_avatar_url.up.sql | 1 - .../sql/14_add_board_description.up.sql | 1 - .../sql/14_add_borad_description.down.sql | 1 - .../migrations/sql/1_initial_schema.up.sql | 242 ++++++++++++------ .../2_update_board_sessions_table.down.sql | 1 - .../sql/2_update_board_sessions_table.up.sql | 1 - .../sql/3_add_avatar_column.down.sql | 2 - .../migrations/sql/3_add_avatar_column.up.sql | 2 - .../migrations/sql/4_add_timer_start.down.sql | 1 - .../migrations/sql/4_add_timer_start.up.sql | 1 - .../sql/5_add_key_rotation.down.sql | 2 - .../migrations/sql/5_add_key_rotation.up.sql | 2 - .../sql/6_add_note_assignments.down.sql | 1 - .../sql/6_add_note_assignments.up.sql | 7 - .../sql/7_add_azure_ad_auth.down.sql | 1 - .../migrations/sql/7_add_azure_ad_auth.up.sql | 9 - .../migrations/sql/8_add_reactions.down.sql | 3 - .../migrations/sql/8_add_reactions.up.sql | 16 -- ..._analytics_board_deletion_trigger.down.sql | 3 - ...dd_analytics_board_deletion_trigger.up.sql | 62 ----- 27 files changed, 168 insertions(+), 211 deletions(-) delete mode 100644 server/src/database/migrations/sql/10_add_lock_board.down.sql delete mode 100644 server/src/database/migrations/sql/10_add_lock_board.up.sql delete mode 100644 server/src/database/migrations/sql/11_remove_note_assignments.down.sql delete mode 100644 server/src/database/migrations/sql/11_remove_note_assignments.up.sql delete mode 100644 server/src/database/migrations/sql/12_add_banned_column.down.sql delete mode 100644 server/src/database/migrations/sql/12_add_banned_column.up.sql delete mode 100644 server/src/database/migrations/sql/13_increase_gauth_avatar_url.down.sql delete mode 100644 server/src/database/migrations/sql/13_increase_gauth_avatar_url.up.sql delete mode 100644 server/src/database/migrations/sql/14_add_board_description.up.sql delete mode 100644 server/src/database/migrations/sql/14_add_borad_description.down.sql delete mode 100644 server/src/database/migrations/sql/2_update_board_sessions_table.down.sql delete mode 100644 server/src/database/migrations/sql/2_update_board_sessions_table.up.sql delete mode 100644 server/src/database/migrations/sql/3_add_avatar_column.down.sql delete mode 100644 server/src/database/migrations/sql/3_add_avatar_column.up.sql delete mode 100644 server/src/database/migrations/sql/4_add_timer_start.down.sql delete mode 100644 server/src/database/migrations/sql/4_add_timer_start.up.sql delete mode 100644 server/src/database/migrations/sql/5_add_key_rotation.down.sql delete mode 100644 server/src/database/migrations/sql/5_add_key_rotation.up.sql delete mode 100644 server/src/database/migrations/sql/6_add_note_assignments.down.sql delete mode 100644 server/src/database/migrations/sql/6_add_note_assignments.up.sql delete mode 100644 server/src/database/migrations/sql/7_add_azure_ad_auth.down.sql delete mode 100644 server/src/database/migrations/sql/7_add_azure_ad_auth.up.sql delete mode 100644 server/src/database/migrations/sql/8_add_reactions.down.sql delete mode 100644 server/src/database/migrations/sql/8_add_reactions.up.sql delete mode 100644 server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.down.sql delete mode 100644 server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.up.sql diff --git a/server/src/database/migrations/sql/10_add_lock_board.down.sql b/server/src/database/migrations/sql/10_add_lock_board.down.sql deleted file mode 100644 index 7b52ec0040..0000000000 --- a/server/src/database/migrations/sql/10_add_lock_board.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS boards DROP COLUMN IF EXISTS allow_editing; \ No newline at end of file diff --git a/server/src/database/migrations/sql/10_add_lock_board.up.sql b/server/src/database/migrations/sql/10_add_lock_board.up.sql deleted file mode 100644 index 6fdd5821f6..0000000000 --- a/server/src/database/migrations/sql/10_add_lock_board.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS boards ADD COLUMN allow_editing boolean NOT NULL DEFAULT true; \ No newline at end of file diff --git a/server/src/database/migrations/sql/11_remove_note_assignments.down.sql b/server/src/database/migrations/sql/11_remove_note_assignments.down.sql deleted file mode 100644 index e229c767cb..0000000000 --- a/server/src/database/migrations/sql/11_remove_note_assignments.down.sql +++ /dev/null @@ -1,7 +0,0 @@ -create table assignments -( - id uuid default gen_random_uuid() not null primary key, - "board" uuid not null references boards ON DELETE CASCADE, - "note" uuid not null references notes ON DELETE CASCADE, - name varchar(64) not null -); diff --git a/server/src/database/migrations/sql/11_remove_note_assignments.up.sql b/server/src/database/migrations/sql/11_remove_note_assignments.up.sql deleted file mode 100644 index 058ca84e83..0000000000 --- a/server/src/database/migrations/sql/11_remove_note_assignments.up.sql +++ /dev/null @@ -1 +0,0 @@ -drop table if exists assignments cascade; diff --git a/server/src/database/migrations/sql/12_add_banned_column.down.sql b/server/src/database/migrations/sql/12_add_banned_column.down.sql deleted file mode 100644 index 060f5cee8b..0000000000 --- a/server/src/database/migrations/sql/12_add_banned_column.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS board_sessions DROP COLUMN IF EXISTS banned; \ No newline at end of file diff --git a/server/src/database/migrations/sql/12_add_banned_column.up.sql b/server/src/database/migrations/sql/12_add_banned_column.up.sql deleted file mode 100644 index 812d48a36f..0000000000 --- a/server/src/database/migrations/sql/12_add_banned_column.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS board_sessions ADD COLUMN banned boolean NOT NULL DEFAULT false; \ No newline at end of file diff --git a/server/src/database/migrations/sql/13_increase_gauth_avatar_url.down.sql b/server/src/database/migrations/sql/13_increase_gauth_avatar_url.down.sql deleted file mode 100644 index 875a4faa72..0000000000 --- a/server/src/database/migrations/sql/13_increase_gauth_avatar_url.down.sql +++ /dev/null @@ -1,8 +0,0 @@ -UPDATE google_users -SET avatar_url = CASE - WHEN LENGTH(avatar_url) > 256 THEN 'https://httpcats.com/404.jpg' - ELSE avatar_url -END; - -ALTER TABLE google_users -ALTER COLUMN avatar_url TYPE varchar(256); diff --git a/server/src/database/migrations/sql/13_increase_gauth_avatar_url.up.sql b/server/src/database/migrations/sql/13_increase_gauth_avatar_url.up.sql deleted file mode 100644 index 5a24b194fa..0000000000 --- a/server/src/database/migrations/sql/13_increase_gauth_avatar_url.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS google_users ALTER COLUMN avatar_url TYPE varchar(2048); diff --git a/server/src/database/migrations/sql/14_add_board_description.up.sql b/server/src/database/migrations/sql/14_add_board_description.up.sql deleted file mode 100644 index 20732a6441..0000000000 --- a/server/src/database/migrations/sql/14_add_board_description.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS boards ADD COLUMN description VARCHAR(300); diff --git a/server/src/database/migrations/sql/14_add_borad_description.down.sql b/server/src/database/migrations/sql/14_add_borad_description.down.sql deleted file mode 100644 index f22106fd0b..0000000000 --- a/server/src/database/migrations/sql/14_add_borad_description.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS boards DROP COLUMN IF EXISTS description; diff --git a/server/src/database/migrations/sql/1_initial_schema.up.sql b/server/src/database/migrations/sql/1_initial_schema.up.sql index cfadb020cc..6d226c18f1 100644 --- a/server/src/database/migrations/sql/1_initial_schema.up.sql +++ b/server/src/database/migrations/sql/1_initial_schema.up.sql @@ -1,4 +1,4 @@ -create type account_type as enum ('ANONYMOUS', 'GOOGLE', 'GITHUB', 'MICROSOFT', 'APPLE'); +create type account_type as enum ('ANONYMOUS', 'GOOGLE', 'GITHUB', 'MICROSOFT', 'APPLE', 'AZURE_AD'); create type access_policy as enum ('PUBLIC', 'BY_PASSPHRASE', 'BY_INVITE'); create type board_session_request_status as enum ('PENDING', 'ACCEPTED', 'REJECTED'); create type session_role as enum ('OWNER', 'PARTICIPANT', 'MODERATOR'); @@ -7,135 +7,229 @@ create type color as enum ('backlog-blue' , 'grooming-green' , 'lean-lilac' , 'o create table users ( - id uuid default gen_random_uuid() not null primary key, - "created_at" timestamptz default now(), - name varchar(64) not null, - account_type account_type not null + id uuid default gen_random_uuid() not null primary key, + "created_at" timestamptz default now(), + name varchar(64) not null, + account_type account_type not null, + "avatar" JSONB, + key_migration date ); create table github_users ( - "user" uuid not null references users ON DELETE CASCADE, - id varchar(64) not null unique, - name varchar(64) not null, - avatar_url varchar(256) + "user" uuid not null references users ON DELETE CASCADE, + id varchar(64) not null unique, + name varchar(64) not null, + avatar_url varchar(256) ); create table google_users ( - "user" uuid not null references users ON DELETE CASCADE, - id varchar(64) not null unique, - name varchar(64) not null, - avatar_url varchar(256) + "user" uuid not null references users ON DELETE CASCADE, + id varchar(64) not null unique, + name varchar(64) not null, + avatar_url varchar(2048) ); create table microsoft_users ( - "user" uuid not null references users ON DELETE CASCADE, - id varchar(64) not null unique, - name varchar(64) not null, - avatar_url varchar(256) + "user" uuid not null references users ON DELETE CASCADE, + id varchar(64) not null unique, + name varchar(64) not null, + avatar_url varchar(256) +); + +create table azure_ad_users +( + "user" uuid not null references users ON DELETE CASCADE, + id varchar(64) not null unique, + name varchar(64) not null, + avatar_url varchar(256) ); create table apple_users ( - "user" uuid not null references users ON DELETE CASCADE, - id varchar(64) not null unique, - name varchar(64) not null, - avatar_url varchar(256) + "user" uuid not null references users ON DELETE CASCADE, + id varchar(64) not null unique, + name varchar(64) not null, + avatar_url varchar(256) ); create table boards ( - id uuid default gen_random_uuid() not null primary key, - created_at timestamptz default now(), - "name" varchar(128), - access_policy access_policy not null DEFAULT 'PUBLIC', - passphrase varchar(128), - salt varchar(32), - show_authors boolean not null DEFAULT true, - show_notes_of_other_users boolean not null DEFAULT true, - allow_stacking boolean not null DEFAULT true, - timer_end timestamptz + id uuid default gen_random_uuid() not null primary key, + created_at timestamptz default now(), + "name" varchar(128), + description varchar(300), + access_policy access_policy not null DEFAULT 'PUBLIC', + passphrase varchar(128), + salt varchar(32), + show_authors boolean not null DEFAULT true, + show_notes_of_other_users boolean not null DEFAULT true, + allow_stacking boolean not null DEFAULT true, + timer_start timestamptz, + timer_end timestamptz, + show_note_reactions boolean not null DEFAULT true, + allow_editing boolean not null DEFAULT true ); create table columns ( - id uuid default gen_random_uuid() not null primary key, - "board" uuid not null references boards ON DELETE CASCADE, - name varchar(128) not null, - check (name <> ''), - color color not null default 'backlog-blue', - "visible" boolean DEFAULT false, - "index" int not null DEFAULT 0 + id uuid default gen_random_uuid() not null primary key, + "board" uuid not null references boards ON DELETE CASCADE, + name varchar(128) not null, + check (name <> ''), + color color not null default 'backlog-blue', + "visible" boolean DEFAULT false, + "index" int not null DEFAULT 0 ); create index columns_board_index on columns (board); create table board_session_requests ( - "user" uuid not null references users ON DELETE CASCADE, - "board" uuid not null references boards ON DELETE CASCADE, - "status" board_session_request_status not null DEFAULT 'PENDING', - "created_at" timestamptz not null DEFAULT now(), - PRIMARY KEY ("user", board) + "user" uuid not null references users ON DELETE CASCADE, + "board" uuid not null references boards ON DELETE CASCADE, + "status" board_session_request_status not null DEFAULT 'PENDING', + "created_at" timestamptz not null DEFAULT now(), + PRIMARY KEY ("user", board) ); create index board_session_requests_board_index on board_session_requests (board); create table board_sessions ( - "user" uuid not null references users ON DELETE CASCADE, - "board" uuid not null references boards ON DELETE CASCADE, - "show_hidden_columns" boolean not null DEFAULT false, - "connected" boolean not null DEFAULT false, - "ready" boolean not null DEFAULT false, - raised_hand boolean not null DEFAULT false, - "role" session_role not null, - "created_at" timestamptz not null DEFAULT now(), - PRIMARY KEY ("user", board) + "user" uuid not null references users ON DELETE CASCADE, + "board" uuid not null references boards ON DELETE CASCADE, + "show_hidden_columns" boolean not null DEFAULT true, + "connected" boolean not null DEFAULT false, + "ready" boolean not null DEFAULT false, + raised_hand boolean not null DEFAULT false, + "role" session_role not null, + "created_at" timestamptz not null DEFAULT now(), + banned boolean not null DEFAULT false, + PRIMARY KEY ("user", board) ); create index board_sessions_board_index on board_sessions (board); create table notes ( - id uuid default gen_random_uuid() not null primary key, - created_at timestamptz not null DEFAULT now(), - "author" uuid not null references users ON DELETE CASCADE, - "board" uuid not null references boards ON DELETE CASCADE, - "column" uuid not null references columns ON DELETE CASCADE, - text varchar(2048) not null, - check (text <> ''), - "rank" int not null DEFAULT 0 + id uuid default gen_random_uuid() not null primary key, + created_at timestamptz not null DEFAULT now(), + "author" uuid not null references users ON DELETE CASCADE, + "board" uuid not null references boards ON DELETE CASCADE, + "column" uuid not null references columns ON DELETE CASCADE, + text varchar(2048) not null, + check (text <> ''), + "rank" int not null DEFAULT 0 ); create index notes_board_index on notes (board); create index notes_column_index on notes ("column"); alter table notes - add "stack" uuid references notes ON DELETE CASCADE; + add "stack" uuid references notes ON DELETE CASCADE; create index notes_stack_index on notes (stack); alter table boards - add shared_note uuid references notes; + add shared_note uuid references notes; create table votings ( - id uuid default gen_random_uuid() not null primary key, - created_at timestamptz not null default now(), - "board" uuid not null references boards ON DELETE CASCADE, - vote_limit int not null, - allow_multiple_votes boolean not null DEFAULT true, - show_votes_of_others boolean not null DEFAULT false, - "status" voting_status not null DEFAULT 'OPEN' + id uuid default gen_random_uuid() not null primary key, + created_at timestamptz not null default now(), + "board" uuid not null references boards ON DELETE CASCADE, + vote_limit int not null, + allow_multiple_votes boolean not null DEFAULT true, + show_votes_of_others boolean not null DEFAULT false, + "status" voting_status not null DEFAULT 'OPEN' ); alter table boards - add show_voting uuid references votings; + add show_voting uuid references votings; create table votes ( - "board" uuid not null references boards ON DELETE CASCADE, - "voting" uuid not null references votings ON DELETE CASCADE, - "user" uuid not null references users ON DELETE CASCADE, - "note" uuid not null references notes ON DELETE CASCADE + "board" uuid not null references boards ON DELETE CASCADE, + "voting" uuid not null references votings ON DELETE CASCADE, + "user" uuid not null references users ON DELETE CASCADE, + "note" uuid not null references notes ON DELETE CASCADE ); + +CREATE TABLE reactions +( + "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(), + "note" UUID NOT NULL REFERENCES notes ON DELETE CASCADE, + "user" UUID NOT NULL REFERENCES users ON DELETE CASCADE, + /* CLDR short name in order to allow custom emojis */ + "reaction_type" VARCHAR(50) NOT NULL +); +create index reactions_note_index on reactions (note); + +create table deleted_boards +( + id uuid not null primary key, + access_policy access_policy, + total_columns int, + hidden_columns int, + total_notes int, + hidden_notes int, + first_note_created timestamptz, + last_note_created timestamptz, + avg_chars_per_note int, + total_participants int, + total_moderators int, + total_votes int, + total_votings int, + created_at timestamptz, + deleted_at timestamptz default now() + ); + +CREATE FUNCTION record_deleted_board_statistics() RETURNS TRIGGER AS $$ +DECLARE + total_columns int; + hidden_columns int; + total_notes int; + hidden_notes int; + first_note_created timestamptz; + last_note_created timestamptz; + avg_chars_per_note int; + total_participants int; + total_moderators int; + total_votes int; + total_votings int; + +BEGIN + -- Retrieve all needed stats +SELECT count(id) INTO total_columns FROM columns WHERE board = OLD.id; +SELECT count(id) INTO hidden_columns FROM columns c WHERE board = OLD.id AND c."visible" = false; + +SELECT count(id) INTO total_notes FROM notes WHERE board = OLD.id; +SELECT count(n.id) INTO hidden_notes FROM notes n INNER JOIN columns c ON n."column" = c.id +WHERE c."visible" = false AND n."board" = OLD.id; +SELECT min(created_at) INTO first_note_created FROM notes WHERE board = OLD.id; +SELECT max(created_at) INTO last_note_created FROM notes WHERE board = OLD.id; +SELECT AVG(LENGTH(text)) INTO avg_chars_per_note FROM notes WHERE board = OLD.id; + +SELECT count(user) INTO total_participants FROM board_sessions s WHERE s.board = OLD.id AND s.role = 'PARTICIPANT'; +SELECT count(user) INTO total_moderators FROM board_sessions s WHERE s.board = OLD.id AND s.role = 'OWNER'OR s.role = 'MODERATOR'; + +SELECT count(board) INTO total_votes FROM votes WHERE board = OLD.id; +SELECT count(id) INTO total_votings FROM votings WHERE board = OLD.id; + +-- Insert data +INSERT INTO deleted_boards (id, access_policy, total_columns, hidden_columns, total_notes, hidden_notes, + avg_chars_per_note, first_note_created, last_note_created, total_participants, + total_moderators, total_votes, total_votings, created_at) +VALUES (OLD.id, OLD.access_policy, total_columns, hidden_columns, total_notes, hidden_notes, avg_chars_per_note, + first_note_created, last_note_created, total_participants, total_moderators, total_votes, total_votings, + OLD.created_at); +RETURN OLD; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER before_delete_board + BEFORE DELETE + ON boards + FOR EACH ROW + EXECUTE FUNCTION record_deleted_board_statistics(); + diff --git a/server/src/database/migrations/sql/2_update_board_sessions_table.down.sql b/server/src/database/migrations/sql/2_update_board_sessions_table.down.sql deleted file mode 100644 index cad33f8962..0000000000 --- a/server/src/database/migrations/sql/2_update_board_sessions_table.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS board_sessions ALTER COLUMN show_hidden_columns SET DEFAULT false; diff --git a/server/src/database/migrations/sql/2_update_board_sessions_table.up.sql b/server/src/database/migrations/sql/2_update_board_sessions_table.up.sql deleted file mode 100644 index f5bf53d3f9..0000000000 --- a/server/src/database/migrations/sql/2_update_board_sessions_table.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS board_sessions ALTER COLUMN show_hidden_columns SET DEFAULT true; diff --git a/server/src/database/migrations/sql/3_add_avatar_column.down.sql b/server/src/database/migrations/sql/3_add_avatar_column.down.sql deleted file mode 100644 index 7e49137b9f..0000000000 --- a/server/src/database/migrations/sql/3_add_avatar_column.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table users - drop column if exists avatar; diff --git a/server/src/database/migrations/sql/3_add_avatar_column.up.sql b/server/src/database/migrations/sql/3_add_avatar_column.up.sql deleted file mode 100644 index 98502da997..0000000000 --- a/server/src/database/migrations/sql/3_add_avatar_column.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table users - add column if not exists avatar JSONB; diff --git a/server/src/database/migrations/sql/4_add_timer_start.down.sql b/server/src/database/migrations/sql/4_add_timer_start.down.sql deleted file mode 100644 index d90aa80c45..0000000000 --- a/server/src/database/migrations/sql/4_add_timer_start.down.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS boards DROP COLUMN IF EXISTS timer_start; diff --git a/server/src/database/migrations/sql/4_add_timer_start.up.sql b/server/src/database/migrations/sql/4_add_timer_start.up.sql deleted file mode 100644 index 1da8a921c1..0000000000 --- a/server/src/database/migrations/sql/4_add_timer_start.up.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE IF EXISTS boards ADD COLUMN timer_start timestamptz; diff --git a/server/src/database/migrations/sql/5_add_key_rotation.down.sql b/server/src/database/migrations/sql/5_add_key_rotation.down.sql deleted file mode 100644 index 7e49137b9f..0000000000 --- a/server/src/database/migrations/sql/5_add_key_rotation.down.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table users - drop column if exists avatar; diff --git a/server/src/database/migrations/sql/5_add_key_rotation.up.sql b/server/src/database/migrations/sql/5_add_key_rotation.up.sql deleted file mode 100644 index b1dbf4ec46..0000000000 --- a/server/src/database/migrations/sql/5_add_key_rotation.up.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table users - add column if not exists key_migration date; diff --git a/server/src/database/migrations/sql/6_add_note_assignments.down.sql b/server/src/database/migrations/sql/6_add_note_assignments.down.sql deleted file mode 100644 index 058ca84e83..0000000000 --- a/server/src/database/migrations/sql/6_add_note_assignments.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table if exists assignments cascade; diff --git a/server/src/database/migrations/sql/6_add_note_assignments.up.sql b/server/src/database/migrations/sql/6_add_note_assignments.up.sql deleted file mode 100644 index e229c767cb..0000000000 --- a/server/src/database/migrations/sql/6_add_note_assignments.up.sql +++ /dev/null @@ -1,7 +0,0 @@ -create table assignments -( - id uuid default gen_random_uuid() not null primary key, - "board" uuid not null references boards ON DELETE CASCADE, - "note" uuid not null references notes ON DELETE CASCADE, - name varchar(64) not null -); diff --git a/server/src/database/migrations/sql/7_add_azure_ad_auth.down.sql b/server/src/database/migrations/sql/7_add_azure_ad_auth.down.sql deleted file mode 100644 index 5f6df420b5..0000000000 --- a/server/src/database/migrations/sql/7_add_azure_ad_auth.down.sql +++ /dev/null @@ -1 +0,0 @@ -drop table if exists azure_ad_users; diff --git a/server/src/database/migrations/sql/7_add_azure_ad_auth.up.sql b/server/src/database/migrations/sql/7_add_azure_ad_auth.up.sql deleted file mode 100644 index 81c4dc2150..0000000000 --- a/server/src/database/migrations/sql/7_add_azure_ad_auth.up.sql +++ /dev/null @@ -1,9 +0,0 @@ -alter type account_type add value 'AZURE_AD'; - -create table azure_ad_users -( - "user" uuid not null references users ON DELETE CASCADE, - id varchar(64) not null unique, - name varchar(64) not null, - avatar_url varchar(256) -); diff --git a/server/src/database/migrations/sql/8_add_reactions.down.sql b/server/src/database/migrations/sql/8_add_reactions.down.sql deleted file mode 100644 index 3ee61caa93..0000000000 --- a/server/src/database/migrations/sql/8_add_reactions.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE IF EXISTS reactions; - -ALTER TABLE IF EXISTS boards DROP COLUMN IF EXISTS show_note_reactions; diff --git a/server/src/database/migrations/sql/8_add_reactions.up.sql b/server/src/database/migrations/sql/8_add_reactions.up.sql deleted file mode 100644 index 407cd0dd28..0000000000 --- a/server/src/database/migrations/sql/8_add_reactions.up.sql +++ /dev/null @@ -1,16 +0,0 @@ -/* this table includes all reactions that have been made to notes. - every reaction is bound to a note that it sits on, as well as - the user that made the reaction. */ -CREATE TABLE reactions ( - "id" UUID PRIMARY KEY DEFAULT gen_random_uuid(), - "note" UUID NOT NULL REFERENCES notes ON DELETE CASCADE, - "user" UUID NOT NULL REFERENCES users ON DELETE CASCADE, - /* CLDR short name in order to allow custom emojis */ - "reaction_type" VARCHAR(50) NOT NULL -); - -/* creating the index on notes so we find the reactions for that note faster */ -CREATE INDEX reactions_note_index ON reactions (note); - -/* also alter board to add option whether to show the reactions to all users */ -ALTER TABLE IF EXISTS boards ADD COLUMN show_note_reactions bool DEFAULT true; diff --git a/server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.down.sql b/server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.down.sql deleted file mode 100644 index 629e52f43f..0000000000 --- a/server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.down.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP TABLE IF EXISTS deleted_boards; -DROP TRIGGER IF EXISTS before_delete_board ON boards; -DROP FUNCTION IF EXISTS record_deleted_board_statistics(); \ No newline at end of file diff --git a/server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.up.sql b/server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.up.sql deleted file mode 100644 index 0381aa6b87..0000000000 --- a/server/src/database/migrations/sql/9_add_analytics_board_deletion_trigger.up.sql +++ /dev/null @@ -1,62 +0,0 @@ -CREATE TABLE IF NOT EXISTS deleted_boards( - id uuid not null primary key, - access_policy access_policy, - total_columns int, - hidden_columns int, - total_notes int, - hidden_notes int, - first_note_created timestamptz, - last_note_created timestamptz, - avg_chars_per_note int, - total_participants int, - total_moderators int, - total_votes int, - total_votings int, - created_at timestamptz, - deleted_at timestamptz default now() -); - -CREATE OR REPLACE FUNCTION record_deleted_board_statistics() - RETURNS TRIGGER AS $$ - DECLARE - total_columns int; - hidden_columns int; - total_notes int; - hidden_notes int; - first_note_created timestamptz; - last_note_created timestamptz; - avg_chars_per_note int; - total_participants int; - total_moderators int; - total_votes int; - total_votings int; - - BEGIN - -- Retrieve all needed stats - SELECT count(id) INTO total_columns FROM columns WHERE board = OLD.id; - SELECT count(id) INTO hidden_columns FROM columns c WHERE board = OLD.id AND c."visible" = false; - - SELECT count(id) INTO total_notes FROM notes WHERE board = OLD.id; - SELECT count(n.id) INTO hidden_notes FROM notes n INNER JOIN columns c ON n."column" = c.id WHERE c."visible" = false AND n."board" = OLD.id; - SELECT min(created_at) INTO first_note_created FROM notes WHERE board = OLD.id; - SELECT max(created_at) INTO last_note_created FROM notes WHERE board = OLD.id; - SELECT AVG(LENGTH(text)) INTO avg_chars_per_note FROM notes WHERE board = OLD.id; - - SELECT count(user) INTO total_participants FROM board_sessions s WHERE s.board = OLD.id AND s.role = 'PARTICIPANT'; - SELECT count(user) INTO total_moderators FROM board_sessions s WHERE s.board = OLD.id AND s.role = 'OWNER' OR s.role = 'MODERATOR'; - - SELECT count(board) INTO total_votes FROM votes WHERE board = OLD.id; - SELECT count(id) INTO total_votings FROM votings WHERE board = OLD.id; - - -- Insert data - INSERT INTO deleted_boards (id, access_policy, total_columns, hidden_columns, total_notes, hidden_notes, avg_chars_per_note, first_note_created, last_note_created, total_participants, total_moderators, total_votes, total_votings, created_at) - VALUES (OLD.id, OLD.access_policy, total_columns, hidden_columns, total_notes, hidden_notes, avg_chars_per_note, first_note_created, last_note_created, total_participants, total_moderators, total_votes, total_votings, OLD.created_at); - RETURN OLD; - END; - $$ LANGUAGE plpgsql; - -CREATE TRIGGER before_delete_board - BEFORE DELETE ON boards - FOR EACH ROW - EXECUTE FUNCTION record_deleted_board_statistics(); - \ No newline at end of file From 097d29fcef4c114f952f459e77160e78966e02a0 Mon Sep 17 00:00:00 2001 From: Mateo Date: Thu, 16 May 2024 09:07:29 +0200 Subject: [PATCH 2/2] updated initial_schema.down.sql --- .../migrations/sql/1_initial_schema.down.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/src/database/migrations/sql/1_initial_schema.down.sql b/server/src/database/migrations/sql/1_initial_schema.down.sql index c11f9fbdbd..2aed590202 100644 --- a/server/src/database/migrations/sql/1_initial_schema.down.sql +++ b/server/src/database/migrations/sql/1_initial_schema.down.sql @@ -5,10 +5,21 @@ drop type if exists session_role cascade; drop type if exists voting_status cascade; drop table if exists users cascade; +drop table if exists github_users cascade; +drop table if exists google_users cascade; +drop table if exists microsoft_users cascade; +drop table if exists azure_ad_users cascade; +drop table if exists apple_users cascade; drop table if exists boards cascade; drop table if exists "columns" cascade; drop table if exists board_session_requests cascade; drop table if exists board_sessions cascade; drop table if exists notes cascade; drop table if exists votings cascade; -drop table if exists votes cascade; \ No newline at end of file +drop table if exists votes cascade; +drop table if exists ractions cascade; +drop table if exists deleted_boards cascade; + +DROP FUNCTION record_deleted_board_statistics(); + +DROP TRIGGER before_delete_board ON boards;