diff --git a/src/migrations/20240904084114-add-update-feature-dependency-editor.js b/src/migrations/20240904084114-add-update-feature-dependency-editor.js index 42873e9a476d..06c841f4d30e 100644 --- a/src/migrations/20240904084114-add-update-feature-dependency-editor.js +++ b/src/migrations/20240904084114-add-update-feature-dependency-editor.js @@ -1,7 +1,14 @@ exports.up = function (db, cb) { db.runSql( ` - INSERT INTO role_permission (role_id, permission) SELECT id, 'UPDATE_FEATURE_DEPENDENCY' FROM roles WHERE name = 'Editor' LIMIT 1; + INSERT INTO role_permission (role_id, permission) SELECT id, 'UPDATE_FEATURE_DEPENDENCY' FROM roles WHERE name = 'Editor' + AND EXISTS (SELECT 1 FROM roles WHERE name = 'Editor') + AND NOT EXISTS ( + SELECT 1 + FROM role_permission rp + WHERE rp.role_id = (SELECT id FROM roles WHERE name = 'Editor') + AND rp.permission = 'UPDATE_FEATURE_DEPENDENCY' + ); `, cb ); @@ -10,7 +17,8 @@ exports.up = function (db, cb) { exports.down = function (db, cb) { db.runSql( ` - DELETE FROM role_permission WHERE role_id = (SELECT id FROM roles WHERE name = 'Editor') AND permission = 'UPDATE_FEATURE_DEPENDENCY'; + DELETE FROM role_permission WHERE role_id = (SELECT id FROM roles WHERE name = 'Editor') AND permission = 'UPDATE_FEATURE_DEPENDENCY' + AND EXISTS (SELECT 1 FROM roles WHERE name = 'Editor'); `, cb );