cleanup: refactor api architecture & add user roles
This commit is contained in:
@ -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,
|
||||
|
@ -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');
|
||||
|
6
api/migrations/0037_add-project_member-table.up.sql
Normal file
6
api/migrations/0037_add-project_member-table.up.sql
Normal 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
|
||||
);
|
9
api/migrations/0038_add-role-table.up.sql
Normal file
9
api/migrations/0038_add-role-table.up.sql
Normal 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');
|
@ -0,0 +1,2 @@
|
||||
ALTER TABLE user_account ADD COLUMN role_code text
|
||||
NOT NULL REFERENCES role(code) ON DELETE CASCADE DEFAULT 'member';
|
@ -0,0 +1 @@
|
||||
ALTER TABLE project_member ADD UNIQUE (project_id, user_id);
|
@ -0,0 +1,2 @@
|
||||
ALTER TABLE project_member ADD COLUMN role_code TEXT
|
||||
NOT NULL REFERENCES role(code) ON DELETE CASCADE DEFAULT 'member';
|
@ -0,0 +1 @@
|
||||
ALTER TABLE user_account ALTER COLUMN profile_avatar_url SET DEFAULT null;
|
@ -0,0 +1 @@
|
||||
ALTER TABLE team_member ADD COLUMN role_code TEXT NOT NULL REFERENCES role(code) ON DELETE CASCADE;
|
4
api/migrations/0044_add-owner-to-team-table.up.sql
Normal file
4
api/migrations/0044_add-owner-to-team-table.up.sql
Normal 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;
|
Reference in New Issue
Block a user