1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/migrations/20210428103924-patch-admin_role.js
Ivar Conradi Østhus 48e09dbc2a fix: add migration patch
This patch will fix issues introduced in Unleash v3.13.0. It only
affects users trying to upgrade from v3 to v4 and has been using
v3.13.0 which contained an incorrect migration file.
2022-02-24 14:08:41 +01:00

28 lines
706 B
JavaScript

'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();
};