1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/src/migrations/20230208093750-assign-project-api-token-permissions-owner.js

30 lines
1016 B
JavaScript
Raw Normal View History

exports.up = function (db, cb) {
db.runSql(
`
INSERT INTO role_permission (role_id, permission_id)
SELECT (SELECT id as role_id from roles WHERE name = 'Owner' LIMIT 1),
p.id as permission_id
FROM permissions p
WHERE p.permission IN
('READ_PROJECT_API_TOKEN',
'CREATE_PROJECT_API_TOKEN',
'DELETE_PROJECT_API_TOKEN');
`,
cb,
);
};
exports.down = function (db, cb) {
db.runSql(
`
DELETE FROM role_permission
WHERE permission_id IN (SELECT id from permissions WHERE permission IN ('READ_PROJECT_API_TOKEN',
'CREATE_PROJECT_API_TOKEN',
'DELETE_PROJECT_API_TOKEN'))
AND role_id = (SELECT id as role_id from roles WHERE name = 'Owner' LIMIT 1)
`,
cb,
);
};