cleanup: refactor api architecture & add user roles

This commit is contained in:
Jordan Knott
2020-07-04 18:02:57 -05:00
parent a3958595cd
commit eaffaa70df
141 changed files with 12487 additions and 3792 deletions

View File

@ -1,3 +1,5 @@
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,

View File

@ -3,3 +3,5 @@ CREATE TABLE organization (
created_at timestamptz NOT NULL,
name text NOT NULL
);
INSERT INTO organization (created_at, name) VALUES (NOW(), 'sys_default_organization');

View File

@ -0,0 +1,6 @@
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

@ -0,0 +1,9 @@
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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,4 @@
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;