CREATE TABLE IF NOT EXISTS user_roles (
  user_id INTEGER NOT NULL,
  project_id INTEGER NOT NULL,
  role STRING NOT NULL, -- 'admin' or 'member'
  FOREIGN KEY (user_id) REFERENCES users (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;