User_roles table constraints
This commit is contained in:
parent
b39ce645d6
commit
a749857c98
1 changed files with 10 additions and 1 deletions
|
@ -4,4 +4,13 @@ CREATE TABLE IF NOT EXISTS user_roles (
|
||||||
role STRING NOT NULL, -- 'admin' or 'member'
|
role STRING NOT NULL, -- 'admin' or 'member'
|
||||||
FOREIGN KEY (user_id) REFERENCES users (id)
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
FOREIGN KEY (project_id) REFERENCES projects (id)
|
FOREIGN KEY (project_id) REFERENCES projects (id)
|
||||||
|
PRIMARY KEY (user_id, project_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Make sure that the role is either 'admin' or 'member'
|
||||||
|
CREATE TRIGGER IF NOT EXISTS user_role_admin_or_member
|
||||||
|
BEFORE INSERT ON user_roles
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
SELECT RAISE(ABORT, 'Invalid role') WHERE NEW.role NOT IN ('admin', 'member');
|
||||||
|
END;
|
Loading…
Add table
Reference in a new issue