This commit is contained in:
Jordan Knott
2022-05-06 16:41:52 -05:00
parent 4f5aa2deb8
commit 64093e19f6
2156 changed files with 29717 additions and 80267 deletions

View File

@ -1,8 +0,0 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE refresh_token (
token_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id uuid NOT NULL,
created_at timestamptz NOT NULL,
expires_at timestamptz NOT NULL
);

View File

@ -1,9 +0,0 @@
CREATE TABLE user_account (
user_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
created_at timestamptz NOT NULL,
first_name text NOT NULL,
last_name text NOT NULL,
email text NOT NULL UNIQUE,
username text NOT NULL UNIQUE,
password_hash text NOT NULL
);

View File

@ -1,5 +0,0 @@
CREATE TABLE team (
team_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
created_at timestamptz NOT NULL,
name text NOT NULL
);

View File

@ -1,6 +0,0 @@
CREATE TABLE project (
project_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
team_id uuid NOT NULL REFERENCES team(team_id),
created_at timestamptz NOT NULL,
name text NOT NULL
);

View File

@ -1,7 +0,0 @@
CREATE TABLE task_group (
task_group_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
project_id uuid NOT NULL REFERENCES project(project_id),
created_at timestamptz NOT NULL,
name text NOT NULL,
position float NOT NULL
);

View File

@ -1,7 +0,0 @@
CREATE TABLE task (
task_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_group_id uuid NOT NULL REFERENCES task_group(task_group_id),
created_at timestamptz NOT NULL,
name text NOT NULL,
position float NOT NULL
);

View File

@ -1,7 +0,0 @@
CREATE TABLE organization (
organization_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
created_at timestamptz NOT NULL,
name text NOT NULL
);
INSERT INTO organization (created_at, name) VALUES (NOW(), 'sys_default_organization');

View File

@ -1 +0,0 @@
ALTER TABLE team ADD COLUMN organization_id uuid NOT NULL REFERENCES organization(organization_id);

View File

@ -1,6 +0,0 @@
CREATE TABLE task_assigned (
task_assigned_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_id uuid NOT NULL REFERENCES task(task_id),
user_id uuid NOT NULL REFERENCES user_account(user_id),
assigned_date timestamptz NOT NULL
);

View File

@ -1 +0,0 @@
ALTER TABLE task ADD COLUMN description text;

View File

@ -1,5 +0,0 @@
CREATE TABLE label_color (
label_color_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
color_hex TEXT NOT NULL,
position FLOAT NOT NULL
);

View File

@ -1,7 +0,0 @@
CREATE TABLE project_label (
project_label_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
project_id uuid NOT NULL REFERENCES project(project_id),
label_color_id uuid NOT NULL REFERENCES label_color(label_color_id),
created_date timestamptz NOT NULL,
name text
);

View File

@ -1 +0,0 @@
ALTER TABLE task ADD COLUMN due_date timestamptz;

View File

@ -1 +0,0 @@
ALTER TABLE project ADD COLUMN owner uuid NOT NULL;

View File

@ -1,6 +0,0 @@
CREATE TABLE task_label (
task_label_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_id uuid NOT NULL REFERENCES task(task_id),
project_label_id uuid NOT NULL REFERENCES project_label(project_label_id),
assigned_date timestamptz NOT NULL
);

View File

@ -1 +0,0 @@
ALTER TABLE user_account ADD COLUMN profile_bg_color text NOT NULL DEFAULT '#7367F0';

View File

@ -1,6 +0,0 @@
ALTER TABLE task_assigned
DROP CONSTRAINT task_assigned_task_id_fkey,
ADD CONSTRAINT task_assigned_task_id_fkey
FOREIGN KEY (task_id)
REFERENCES task(task_id)
ON DELETE CASCADE;

View File

@ -1 +0,0 @@
ALTER TABLE label_color ADD COLUMN name TEXT NOT NULL DEFAULT 'needs name';

View File

@ -1 +0,0 @@
ALTER TABLE task_label ADD UNIQUE (project_label_id, task_id);

View File

@ -1,3 +0,0 @@
ALTER TABLE user_account ADD COLUMN full_name TEXT;
UPDATE user_account SET full_name = CONCAT(first_name, ' ', last_name);
ALTER TABLE user_account ALTER COLUMN full_name SET NOT NULL;

View File

@ -1 +0,0 @@
ALTER TABLE user_account DROP COLUMN first_name;

View File

@ -1 +0,0 @@
ALTER TABLE user_account DROP COLUMN last_name;

View File

@ -1 +0,0 @@
ALTER TABLE user_account ADD COLUMN initials TEXT NOT NULL DEFAULT '';

View File

@ -1 +0,0 @@
ALTER TABLE user_account ADD COLUMN profile_avatar_url TEXT;

View File

@ -1,6 +0,0 @@
ALTER TABLE task_label DROP CONSTRAINT task_label_task_id_fkey;
ALTER TABLE task_label
ADD CONSTRAINT task_label_task_id_fkey
FOREIGN KEY (task_id)
REFERENCES task(task_id)
ON DELETE CASCADE;

View File

@ -1,6 +0,0 @@
ALTER TABLE task_assigned DROP CONSTRAINT task_assigned_task_id_fkey;
ALTER TABLE task_assigned
ADD CONSTRAINT task_assigned_task_id_fkey
FOREIGN KEY (task_id)
REFERENCES task(task_id)
ON DELETE CASCADE;

View File

@ -1,6 +0,0 @@
ALTER TABLE task DROP CONSTRAINT task_task_group_id_fkey;
ALTER TABLE task
ADD CONSTRAINT task_task_group_id_fkey
FOREIGN KEY (task_group_id)
REFERENCES task_group(task_group_id)
ON DELETE CASCADE;

View File

@ -1 +0,0 @@
ALTER TABLE task ADD COLUMN complete boolean NOT NULL DEFAULT FALSE;

View File

@ -1,7 +0,0 @@
CREATE TABLE task_checklist (
task_checklist_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_id uuid NOT NULL REFERENCES task(task_id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
name text NOT NULL,
position float NOT NULL
);

View File

@ -1,9 +0,0 @@
CREATE TABLE task_checklist_item (
task_checklist_item_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_checklist_id uuid NOT NULL REFERENCES task_checklist(task_checklist_id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
complete boolean NOT NULL DEFAULT false,
name text NOT NULL,
position float NOT NULL,
due_date timestamptz
);

View File

@ -1,7 +0,0 @@
CREATE TABLE team_member (
team_member_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
team_id uuid NOT NULL REFERENCES team(team_id) ON DELETE CASCADE,
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
UNIQUE(team_id, user_id),
addedDate timestamptz NOT NULL
);

View File

@ -1,6 +0,0 @@
ALTER TABLE project_label DROP CONSTRAINT project_label_project_id_fkey;
ALTER TABLE project_label
ADD CONSTRAINT project_label_project_id_fkey
FOREIGN KEY (project_id)
REFERENCES project(project_id)
ON DELETE CASCADE;

View File

@ -1,6 +0,0 @@
ALTER TABLE task_label DROP CONSTRAINT task_label_project_label_id_fkey;
ALTER TABLE task_label
ADD CONSTRAINT task_label_project_label_id_fkey
FOREIGN KEY (project_label_id)
REFERENCES project_label(project_label_id)
ON DELETE CASCADE;

View File

@ -1,6 +0,0 @@
ALTER TABLE project DROP CONSTRAINT project_team_id_fkey;
ALTER TABLE project
ADD CONSTRAINT project_team_id_fkey
FOREIGN KEY (team_id)
REFERENCES team(team_id)
ON DELETE CASCADE;

View File

@ -1,6 +0,0 @@
ALTER TABLE task_assigned DROP CONSTRAINT task_assigned_user_id_fkey;
ALTER TABLE task_assigned
ADD CONSTRAINT task_assigned_user_id_fkey
FOREIGN KEY (user_id)
REFERENCES user_account(user_id)
ON DELETE CASCADE;

View File

@ -1,5 +0,0 @@
ALTER TABLE refresh_token
ADD CONSTRAINT refresh_token_user_id_fkey
FOREIGN KEY (user_id)
REFERENCES user_account(user_id)
ON DELETE CASCADE;

View File

@ -1,6 +0,0 @@
CREATE TABLE project_member (
project_member_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
project_id uuid NOT NULL REFERENCES project(project_id) ON DELETE CASCADE,
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
added_at timestamptz NOT NULL
);

View File

@ -1,9 +0,0 @@
CREATE TABLE role (
code TEXT PRIMARY KEY,
name TEXT NOT NULL
);
INSERT INTO role VALUES ('owner', 'Owner');
INSERT INTO role VALUES ('admin', 'Admin');
INSERT INTO role VALUES ('member', 'Member');
INSERT INTO role VALUES ('observer', 'Observer');

View File

@ -1,2 +0,0 @@
ALTER TABLE user_account ADD COLUMN role_code text
NOT NULL REFERENCES role(code) ON DELETE CASCADE DEFAULT 'member';

View File

@ -1 +0,0 @@
ALTER TABLE project_member ADD UNIQUE (project_id, user_id);

View File

@ -1,2 +0,0 @@
ALTER TABLE project_member ADD COLUMN role_code TEXT
NOT NULL REFERENCES role(code) ON DELETE CASCADE DEFAULT 'member';

View File

@ -1 +0,0 @@
ALTER TABLE user_account ALTER COLUMN profile_avatar_url SET DEFAULT null;

View File

@ -1 +0,0 @@
ALTER TABLE team_member ADD COLUMN role_code TEXT NOT NULL REFERENCES role(code) ON DELETE CASCADE;

View File

@ -1,4 +0,0 @@
ALTER TABLE team ADD COLUMN owner uuid REFERENCES user_account(user_id) ON DELETE
CASCADE;
UPDATE team SET owner = (SELECT user_id FROM user_account WHERE role_code = 'admin' LIMIT 1);
ALTER TABLE team ALTER COLUMN owner SET NOT NULL;

View File

@ -1,5 +0,0 @@
CREATE TABLE system_options (
option_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
key text NOT NULL UNIQUE,
value text
);

View File

@ -1,2 +0,0 @@
INSERT INTO user_account(created_at, email, initials, username, full_name,
role_code, password_hash) VALUES (NOW(), '', 'SYS', 'system', 'System', 'owner', '');

View File

@ -1,16 +0,0 @@
INSERT INTO label_color (color_hex, position, name ) VALUES ( 'transparent', 0.0, 'no_color' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#e8384f', 1.0, 'red' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#fd612c', 2.0, 'orange' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#fd9a00', 3.0, 'yellow_orange' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#eec300', 4.0, 'yellow' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#a4cf30', 5.0, 'yellow_green' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#62d26f', 6.0, 'green' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#37c5ab', 6.0, 'blue_green' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#20aaea', 6.0, 'aqua' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#4186e0', 6.0, 'blue' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#7a6ff0', 6.0, 'indigo' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#aa62e3', 6.0, 'purple' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#e362e3', 6.0, 'magenta' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#ea4e9d', 6.0, 'hot_pink' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#fc91ad', 6.0, 'pink' );
INSERT INTO label_color (color_hex, position, name ) VALUES ( '#8da3a6', 6.0, 'cool_gray' );

View File

@ -1,6 +0,0 @@
ALTER TABLE task_group DROP CONSTRAINT task_group_project_id_fkey;
ALTER TABLE task_group
ADD CONSTRAINT task_group_project_id_fkey
FOREIGN KEY (project_id)
REFERENCES project(project_id)
ON DELETE CASCADE;

View File

@ -1,4 +0,0 @@
INSERT INTO project_member (user_id, project_id, added_at, role_code)
SELECT owner as user_id, project_id, NOW() as added_at, 'admin' as role_code
FROM project;
ALTER TABLE project DROP COLUMN owner;

View File

@ -1,4 +0,0 @@
INSERT INTO team_member (user_id, team_id, addeddate, role_code)
SELECT owner as user_id, team_id, NOW() as addeddate, 'admin' as role_code
FROM team ON CONFLICT ON CONSTRAINT team_member_team_id_user_id_key DO NOTHING;
ALTER TABLE team DROP COLUMN owner;

View File

@ -1,4 +0,0 @@
ALTER TABLE task ADD COLUMN completed_at timestamptz;
UPDATE task as t1 SET completed_at = NOW()
FROM task as t2
WHERE t1.task_id = t2.task_id AND t1.complete = true;

View File

@ -1 +0,0 @@
ALTER TABLE user_account ADD COLUMN bio text NOT NULL DEFAULT '';

View File

@ -1,15 +0,0 @@
CREATE TABLE notification_object (
notification_object_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
entity_id uuid NOT NULL,
action_type int NOT NULL,
actor_id uuid NOT NULL,
entity_type int NOT NULL,
created_on timestamptz NOT NULL
);
CREATE TABLE notification (
notification_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
notification_object_id uuid REFERENCES notification_object(notification_object_id) ON DELETE CASCADE,
notifier_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
read boolean NOT NULL DEFAULT false
);

View File

@ -1 +0,0 @@
ALTER TABLE project ALTER COLUMN team_id DROP NOT NULL;

View File

@ -1,5 +0,0 @@
CREATE TABLE personal_project (
personal_project_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
project_id uuid NOT NULL REFERENCES project(project_id) ON DELETE CASCADE,
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE
);

View File

@ -1,6 +0,0 @@
CREATE TABLE user_account_invited (
user_account_invited_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
email text NOT NULL UNIQUE,
invited_on timestamptz NOT NULL DEFAULT NOW(),
has_joined boolean NOT NULL DEFAULT false
);

View File

@ -1,7 +0,0 @@
CREATE TABLE project_member_invited (
project_member_invited_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
project_id uuid NOT NULL
REFERENCES project(project_id) ON DELETE CASCADE,
user_account_invited_id uuid NOT NULL
REFERENCES user_account_invited(user_account_invited_id) ON DELETE CASCADE
);

View File

@ -1,2 +0,0 @@
ALTER TABLE user_account ADD COLUMN active boolean NOT NULL DEFAULT false;
UPDATE user_account SET active = true;

View File

@ -1,4 +0,0 @@
CREATE TABLE user_account_confirm_token (
confirm_token_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
email text NOT NULL UNIQUE
);

View File

@ -1,27 +0,0 @@
CREATE TABLE task_activity_type (
task_activity_type_id int PRIMARY KEY,
code text NOT NULL,
template text NOT NULL
);
INSERT INTO task_activity_type (task_activity_type_id, code, template) VALUES
(1, 'task_added_to_task_group', 'added this task to {{ index .Data "TaskGroup" }}'),
(2, 'task_moved_to_task_group', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
(3, 'task_mark_complete', 'marked this task complete'),
(4, 'task_mark_incomplete', 'marked this task incomplete'),
(5, 'task_due_date_changed', 'changed the due date to {{ index .Data "DueDate" }}'),
(6, 'task_due_date_added', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
(7, 'task_due_date_removed', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
(8, 'task_checklist_changed', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
(9, 'task_checklist_added', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}'),
(10, 'task_checklist_removed', 'moved this task from {{ index .Data "PrevTaskGroup" }} to {{ index .Data "CurTaskGroup"}}');
CREATE TABLE task_activity (
task_activity_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
active boolean NOT NULL DEFAULT true,
task_id uuid NOT NULL REFERENCES task(task_id),
created_at timestamptz NOT NULL,
caused_by uuid NOT NULL,
activity_type_id int NOT NULL REFERENCES task_activity_type(task_activity_type_id),
data jsonb
);

View File

@ -1,9 +0,0 @@
CREATE TABLE task_comment (
task_comment_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_id uuid NOT NULL REFERENCES task(task_id),
created_at timestamptz NOT NULL,
updated_at timestamptz,
created_by uuid NOT NULL REFERENCES user_account(user_id),
pinned boolean NOT NULL DEFAULT false,
message TEXT NOT NULL
);

View File

@ -1,13 +0,0 @@
ALTER TABLE task_activity DROP CONSTRAINT task_activity_task_id_fkey;
ALTER TABLE task_activity
ADD CONSTRAINT task_activity_task_id_fkey
FOREIGN KEY (task_id)
REFERENCES task(task_id)
ON DELETE CASCADE;
ALTER TABLE task_comment DROP CONSTRAINT task_comment_task_id_fkey;
ALTER TABLE task_comment
ADD CONSTRAINT task_comment_task_id_fkey
FOREIGN KEY (task_id)
REFERENCES task(task_id)
ON DELETE CASCADE;

View File

@ -1,2 +0,0 @@
ALTER TABLE task ADD COLUMN has_time boolean NOT NULL DEFAULT false;
UPDATE task SET has_time = true;

View File

@ -1 +0,0 @@
ALTER TABLE refresh_token RENAME TO auth_token;

View File

@ -1 +0,0 @@
ALTER TABLE project ADD COLUMN public_on timestamptz;

View File

@ -1,20 +0,0 @@
DROP TABLE notification_object CASCADE;
DROP TABLE notification CASCADE;
CREATE TABLE notification (
notification_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
caused_by uuid NOT NULL,
action_type text NOT NULL,
data jsonb,
created_on timestamptz NOT NULL
);
CREATE TABLE notification_notified (
notified_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
notification_id uuid REFERENCES notification(notification_id) ON DELETE CASCADE,
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
read boolean NOT NULL DEFAULT false,
read_at timestamptz
);
CREATE INDEX idx_notification_pagination ON notification (created_on, notification_id);

View File

@ -1,36 +0,0 @@
CREATE TABLE account_setting_data_type (
data_type_id text PRIMARY KEY
);
INSERT INTO account_setting_data_type VALUES ('string');
CREATE TABLE account_setting (
account_setting_id text PRIMARY KEY,
constrained boolean NOT NULL,
data_type text NOT NULL REFERENCES account_setting_data_type(data_type_id) ON DELETE CASCADE,
constrained_default_value text
REFERENCES account_setting_allowed_values(allowed_value_id) ON DELETE CASCADE,
unconstrained_default_value text
);
INSERT INTO account_setting VALUES ('email_notification_frequency', true, 'string');
CREATE TABLE account_setting_allowed_values (
allowed_value_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
setting_id int NOT NULL REFERENCES account_setting(account_setting_id) ON DELETE CASCADE,
item_value text NOT NULL
);
INSERT INTO account_setting_allowed_values (setting_id, item_value) VALUES (0, 'never');
INSERT INTO account_setting_allowed_values (setting_id, item_value) VALUES (0, 'hourly');
INSERT INTO account_setting_allowed_values (setting_id, item_value) VALUES (0, 'instant');
CREATE TABLE account_setting_value (
account_setting_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
setting_id int NOT NULL REFERENCES account_setting(account_setting_id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
allowed_value_id uuid REFERENCES account_setting_allowed_values(allowed_value_id) ON DELETE CASCADE,
unconstrained_value text
);

View File

@ -1,6 +0,0 @@
CREATE TABLE task_watcher (
task_watcher_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_id uuid NOT NULL REFERENCES task(task_id) ON DELETE CASCADE,
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
watched_at timestamptz NOT NULL
);

View File

@ -1,68 +0,0 @@
CREATE OR REPLACE FUNCTION unique_short_id()
RETURNS TRIGGER AS $$
-- Declare the variables we'll be using.
DECLARE
key TEXT;
qry TEXT;
found TEXT;
BEGIN
-- generate the first part of a query as a string with safely
-- escaped table name, using || to concat the parts
qry := 'SELECT short_id FROM ' || quote_ident(TG_TABLE_NAME) || ' WHERE short_id=';
-- This loop will probably only run once per call until we've generated
-- millions of ids.
LOOP
-- Generate our string bytes and re-encode as a base64 string.
key := encode(gen_random_bytes(6), 'base64');
-- Base64 encoding contains 2 URL unsafe characters by default.
-- The URL-safe version has these replacements.
key := replace(key, '/', '_'); -- url safe replacement
key := replace(key, '+', '-'); -- url safe replacement
-- Concat the generated key (safely quoted) with the generated query
-- and run it.
-- SELECT id FROM "test" WHERE id='blahblah' INTO found
-- Now "found" will be the duplicated id or NULL.
EXECUTE qry || quote_literal(key) INTO found;
-- Check to see if found is NULL.
-- If we checked to see if found = NULL it would always be FALSE
-- because (NULL = NULL) is always FALSE.
IF found IS NULL THEN
-- If we didn't find a collision then leave the LOOP.
EXIT;
END IF;
-- We haven't EXITed yet, so return to the top of the LOOP
-- and try again.
END LOOP;
-- NEW and OLD are available in TRIGGER PROCEDURES.
-- NEW is the mutated row that will actually be INSERTed.
-- We're replacing id, regardless of what it was before
-- with our key variable.
NEW.short_id = key;
-- The RECORD returned here is what will actually be INSERTed,
-- or what the next trigger will get if there is one.
RETURN NEW;
END;
$$ language 'plpgsql';
ALTER TABLE project ADD COLUMN short_id text UNIQUE;
UPDATE project SET short_id = encode(gen_random_bytes(6), 'base64');
ALTER TABLE project ALTER COLUMN short_id SET NOT NULL;
ALTER TABLE project ADD CONSTRAINT project_short_id_unique UNIQUE (short_id);
CREATE TRIGGER trigger_project_short_id BEFORE INSERT ON project FOR EACH ROW EXECUTE PROCEDURE unique_short_id();
ALTER TABLE task ADD COLUMN short_id text UNIQUE;
UPDATE task SET short_id = encode(gen_random_bytes(6), 'base64');
ALTER TABLE task ALTER COLUMN short_id SET NOT NULL;
ALTER TABLE task ADD CONSTRAINT task_short_id_unique UNIQUE (short_id);
CREATE TRIGGER trigger_task_short_id BEFORE INSERT ON task FOR EACH ROW EXECUTE PROCEDURE unique_short_id();

View File

@ -1,15 +0,0 @@
CREATE TABLE task_due_date_reminder_duration (
code text PRIMARY KEY
);
INSERT INTO task_due_date_reminder_duration VALUES ('MINUTE');
INSERT INTO task_due_date_reminder_duration VALUES ('HOUR');
INSERT INTO task_due_date_reminder_duration VALUES ('DAY');
INSERT INTO task_due_date_reminder_duration VALUES ('WEEK');
CREATE TABLE task_due_date_reminder (
due_date_reminder_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
task_id uuid NOT NULL REFERENCES task(task_id) ON DELETE CASCADE,
period int NOT NULL,
duration text NOT NULL REFERENCES task_due_date_reminder_duration(code) ON DELETE CASCADE
);

View File

@ -1 +0,0 @@
ALTER TABLE task_due_date_reminder ADD COLUMN remind_at timestamptz NOT NULL DEFAULT NOW();

View File

@ -1,2 +0,0 @@
ALTER TABLE notification ALTER COLUMN caused_by DROP NOT NULL;
UPDATE notification SET caused_by = null WHERE caused_by = '00000000-0000-0000-0000-000000000000';

View File

@ -0,0 +1,15 @@
-- +goose Up
-- +goose StatementBegin
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE user_account (
user_id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
created_at timestamptz NOT NULL,
fullname text NOT NULL,
username text NOT NULL UNIQUE,
email text NOT NULL UNIQUE,
password_hash text NOT NULL,
avatar_url text
);
-- +goose StatementEnd

View File

@ -0,0 +1,9 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE access_token (
token text PRIMARY KEY,
user_id uuid NOT NULL REFERENCES user_account(user_id) ON DELETE CASCADE,
expires_at timestamptz NOT NULL,
created_at timestamptz NOT NULL
);
-- +goose StatementEnd