From 991cf85a243931ef24495c03dc9e293c68e03c4c Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Tue, 5 Jul 2022 13:16:00 +0000 Subject: [PATCH] Database migration done --- .../20220704115624-add-user-groups.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/migrations/20220704115624-add-user-groups.js diff --git a/src/migrations/20220704115624-add-user-groups.js b/src/migrations/20220704115624-add-user-groups.js new file mode 100644 index 0000000000..45abc75120 --- /dev/null +++ b/src/migrations/20220704115624-add-user-groups.js @@ -0,0 +1,45 @@ +'use strict'; + +exports.up = function (db, callback) { + db.runSql( + ` + create table IF NOT EXISTS groups + ( + id serial primary key, + name text not null, + created_by text, + created_at timestamp with time zone not null default now() + ); + + create table IF NOT EXISTS group_user + ( + group_id integer not null references groups (id) on DELETE CASCADE, + user_id integer not null references users (id) ON DELETE CASCADE, + type text check(type in ('Owner', 'Member')), + created_by text, + created_at timestamp with time zone not null default now(), + primary key (group_id, user_id) + ); + CREATE TABLE IF NOT EXISTS group_role + ( + group_id integer not null references groups (id) ON DELETE CASCADE, + role_id integer not null references roles (id) ON DELETE CASCADE, + created_by text, + created_at TIMESTAMP WITH TIME ZONE DEFAULT now(), + PRIMARY KEY (group_id, role_id) + ); + `, + callback, + ); +}; + +exports.down = function (db, callback) { + db.runSql( + ` + drop table group_role; + drop table group_user; + drop table groups; + `, + callback, + ); +};