salix/db/versions/11060-tealGalax/00-createRoleReviewer.sql

46 lines
1.1 KiB
MySQL
Raw Normal View History

2024-05-31 07:49:58 +00:00
use account;
INSERT INTO account.role
SET name = 'reviewer',
description = 'Revisor de producción',
hasLogin = TRUE,
created = util.VN_CURDATE(),
modified = util.VN_CURDATE(),
editorFk = NULL;
INSERT IGNORE INTO account.roleInherit(
role,
inheritsFrom
)
SELECT r1.id,
r2.id
FROM account.role r1
JOIN account.role r2
WHERE r2.name = 'production'
AND r1.name = 'reviewer'
UNION
SELECT ri.role,
r2.id
FROM account.roleInherit ri
JOIN account.role r1 ON r1.id = ri.role
JOIN account.role r2 ON r2.name = 'reviewer'
WHERE r1.name IN ('claimManager', 'productionBoss')
GROUP BY ri.role;
DELETE ri
FROM account.roleInherit ri
JOIN account.role r1 ON ri.role = r1.id
JOIN account.role r2 ON ri.inheritsFrom = r2.id
WHERE r1.name = 'replenisher'
AND r2.name = 'buyer';
UPDATE salix.ACL
SET principalId = 'reviewer'
WHERE property = 'isInPreparing';
UPDATE account.user u
JOIN vn.workerDepartment wd ON wd.workerFk = u.id
JOIN vn.department d ON wd.departmentFk = d.id
JOIN account.role r ON r.name = 'reviewer'
SET u.role = r.id
WHERE d.name IN ('REVISION', 'PREVIA');