mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
fix: cleanup migrations after the 3.13.0 bug
This commit is contained in:
parent
277012bfe4
commit
9c57ff5ced
24
src/migrations/20210428103922-patch-role-table.js
Normal file
24
src/migrations/20210428103922-patch-role-table.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const async = require('async');
|
||||||
|
|
||||||
|
function resolveRoleName(permissions) {
|
||||||
|
if (!permissions || permissions.length === 0) {
|
||||||
|
return 'Viewer';
|
||||||
|
}
|
||||||
|
if (permissions.includes('ADMIN')) {
|
||||||
|
return 'Admin';
|
||||||
|
}
|
||||||
|
return 'Editor';
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.up = function (db, cb) {
|
||||||
|
db.runSql(
|
||||||
|
'ALTER TABLE roles ADD COLUMN IF NOT EXISTS project text', 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();
|
||||||
|
};
|
15
src/migrations/20210428103924-patch-admin-role-name.js
Normal file
15
src/migrations/20210428103924-patch-admin-role-name.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
exports.up = function (db, cb) {
|
||||||
|
db.runSql(
|
||||||
|
`
|
||||||
|
UPDATE roles set name='Admin' where name='Super User';
|
||||||
|
`,
|
||||||
|
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();
|
||||||
|
};
|
27
src/migrations/20210428103924-patch-admin_role.js
Normal file
27
src/migrations/20210428103924-patch-admin_role.js
Normal file
@ -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();
|
||||||
|
};
|
54
src/migrations/20210428103924-patch-role_permissions.js
Normal file
54
src/migrations/20210428103924-patch-role_permissions.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
exports.up = function (db, cb) {
|
||||||
|
db.runSql(
|
||||||
|
`
|
||||||
|
DO $$
|
||||||
|
declare
|
||||||
|
begin
|
||||||
|
WITH editor AS (
|
||||||
|
SELECT * FROM roles WHERE name in ('Editor', 'Regular') LIMIT 1
|
||||||
|
)
|
||||||
|
|
||||||
|
INSERT INTO role_permission(role_id, project, permission)
|
||||||
|
VALUES
|
||||||
|
((SELECT id from editor), '', 'CREATE_STRATEGY'),
|
||||||
|
((SELECT id from editor), '', 'UPDATE_STRATEGY'),
|
||||||
|
((SELECT id from editor), '', 'DELETE_STRATEGY'),
|
||||||
|
|
||||||
|
((SELECT id from editor), '', 'UPDATE_APPLICATION'),
|
||||||
|
|
||||||
|
((SELECT id from editor), '', 'CREATE_CONTEXT_FIELD'),
|
||||||
|
((SELECT id from editor), '', 'UPDATE_CONTEXT_FIELD'),
|
||||||
|
((SELECT id from editor), '', 'DELETE_CONTEXT_FIELD'),
|
||||||
|
|
||||||
|
((SELECT id from editor), '', 'CREATE_PROJECT'),
|
||||||
|
|
||||||
|
((SELECT id from editor), '', 'CREATE_ADDON'),
|
||||||
|
((SELECT id from editor), '', 'UPDATE_ADDON'),
|
||||||
|
((SELECT id from editor), '', 'DELETE_ADDON'),
|
||||||
|
|
||||||
|
((SELECT id from editor), 'default', 'UPDATE_PROJECT'),
|
||||||
|
((SELECT id from editor), 'default', 'DELETE_PROJECT'),
|
||||||
|
((SELECT id from editor), 'default', 'CREATE_FEATURE'),
|
||||||
|
((SELECT id from editor), 'default', 'UPDATE_FEATURE'),
|
||||||
|
((SELECT id from editor), 'default', 'DELETE_FEATURE');
|
||||||
|
|
||||||
|
-- Clean up duplicates
|
||||||
|
DELETE FROM role_permission p1
|
||||||
|
USING role_permission p2
|
||||||
|
WHERE p1.created_at < p2.created_at -- select the "older" ones
|
||||||
|
AND p1.project = p2.project -- list columns that define duplicates
|
||||||
|
AND p1.permission = p2.permission;
|
||||||
|
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();
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user