fix-staging-seeds #762
@ -222,15 +222,19 @@ CREATE TABLE IF NOT EXISTS "distance" (
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
CREATE UNIQUE INDEX one_role_per_group_per_user ON user_role
|
CREATE TRIGGER prevent_multiple_roles_same_cluster
|
||||||
WHERE EXISTS (
|
BEFORE INSERT ON user_role
|
||||||
SELECT 1
|
BEGIN
|
||||||
FROM role r1
|
SELECT CASE
|
||||||
JOIN role r2 ON r1.id = user_role.role_id
|
WHEN EXISTS (
|
||||||
WHERE r1."group" = r2."group"
|
SELECT 1
|
||||||
AND r2.id IN (
|
FROM user_role ur
|
||||||
SELECT role_id
|
JOIN role r1 ON ur.role_id = r1.id
|
||||||
FROM user_role ur2
|
JOIN role r2 ON r1."cluster" = r2."cluster"
|
||||||
WHERE ur2.user_id = user_role.user_id
|
WHERE ur.user_id = NEW.user_id
|
||||||
)
|
AND r2.id = NEW.role_id
|
||||||
);
|
AND r1.id != NEW.role_id
|
||||||
|
)
|
||||||
|
THEN RAISE(ABORT, 'User already has a role in this cluster')
|
||||||
|
END;
|
||||||
|
END;
|
||||||
|
Loading…
Reference in New Issue
Block a user