From f799f06bf34a82d44a83b7fdc4b5121c9c011029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 23 Feb 2022 11:29:41 +0100 Subject: [PATCH] fix: connect admin user with admin role (bug from 3.13.0) --- .../20210428103924-patch-admin_role.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/migrations/20210428103924-patch-admin_role.js diff --git a/src/migrations/20210428103924-patch-admin_role.js b/src/migrations/20210428103924-patch-admin_role.js new file mode 100644 index 0000000000..891e6f02ab --- /dev/null +++ b/src/migrations/20210428103924-patch-admin_role.js @@ -0,0 +1,27 @@ +'use strict'; + +exports.up = function (db, cb) { + db.runSql( + ` + DO $$ + declare + begin + WITH admin AS ( + SELECT * FROM roles WHERE name in ('Admin', 'Super User') LIMIT 1 + ) + INSERT into role_user(role_id, user_id) + VALUES + ((select id from admin), (select id FROM users where username='admin' LIMIT 1)); + + EXCEPTION WHEN OTHERS THEN + raise notice 'Ignored'; + end; + $$;`, + cb, + ); +}; + +exports.down = function (db, cb) { + // We can't just remove roles for users as we don't know if there has been any manual additions. + cb(); +};