fix backend tests
Some checks failed
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
philipp 2024-10-11 10:29:13 +02:00
parent 9881627186
commit 9bacbb9395

View File

@ -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
BEGIN
SELECT CASE
WHEN EXISTS (
SELECT 1 SELECT 1
FROM role r1 FROM user_role ur
JOIN role r2 ON r1.id = user_role.role_id JOIN role r1 ON ur.role_id = r1.id
WHERE r1."group" = r2."group" JOIN role r2 ON r1."cluster" = r2."cluster"
AND r2.id IN ( WHERE ur.user_id = NEW.user_id
SELECT role_id AND r2.id = NEW.role_id
FROM user_role ur2 AND r1.id != NEW.role_id
WHERE ur2.user_id = user_role.user_id
) )
); THEN RAISE(ABORT, 'User already has a role in this cluster')
END;
END;