1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/src/migrations/20221121114357-add-permission-for-environment-variants.js
Simon Hornby 2a4ca96da2
Permission for variant environments (#2490)
adds permissions for variants per environment
2022-11-22 11:54:04 +02:00

31 lines
1.0 KiB
JavaScript

'use strict';
exports.up = function (db, callback) {
db.runSql(
`
INSERT INTO permissions (permission, display_name, type)
values('UPDATE_FEATURE_ENVIRONMENT_VARIANTS', 'Update variants on environment', 'environment');
INSERT INTO role_permission (role_id, permission_id, environment)
(WITH perm_id as (SELECT id from permissions WHERE permission = 'UPDATE_FEATURE_ENVIRONMENT_VARIANTS')
SELECT rp.role_id, perm_id.id, rp.environment FROM perm_id, role_permission as rp
JOIN permissions p ON p.id = rp.permission_id
WHERE p.permission = 'UPDATE_FEATURE_ENVIRONMENT'
);
`,
callback,
);
};
exports.down = function (db, callback) {
db.runSql(
`
DELETE FROM role_permission WHERE permission_id =
(SELECT id FROM permissions WHERE permission = 'UPDATE_FEATURE_ENVIRONMENT_VARIANTS');
DELETE FROM permissions WHERE permission = 'UPDATE_FEATURE_ENVIRONMENT_VARIANTS';
`,
callback,
);
};