CREATE TABLE calls_team_home_persons ( issuer TEXT NOT NULL, subject TEXT NOT NULL, person_id INTEGER NOT NULL UNIQUE REFERENCES persons(id), PRIMARY KEY(issuer,subject) ); CREATE TRIGGER calls_team_home_person_addressless BEFORE INSERT ON calls_team_home_persons WHEN NOT EXISTS(SELECT 1 FROM persons WHERE id=NEW.person_id AND substr(email,1,10)='home-only:' AND instr(email,'@')=0 AND anonymous=0) BEGIN SELECT RAISE(ABORT,'calls team: refused'); END; CREATE TRIGGER calls_team_home_person_unlinked BEFORE INSERT ON calls_team_home_persons WHEN EXISTS(SELECT 1 FROM home_identity_links WHERE issuer=NEW.issuer AND subject=NEW.subject) BEGIN SELECT RAISE(ABORT,'calls team: refused'); END; CREATE TRIGGER calls_team_home_persons_keep_update BEFORE UPDATE ON calls_team_home_persons BEGIN SELECT RAISE(ABORT,'calls team: refused'); END; CREATE TRIGGER calls_team_home_persons_keep_delete BEFORE DELETE ON calls_team_home_persons BEGIN SELECT RAISE(ABORT,'calls team: refused'); END; CREATE TRIGGER calls_team_link_not_home_only BEFORE INSERT ON home_identity_links WHEN EXISTS(SELECT 1 FROM calls_team_home_persons WHERE (issuer=NEW.issuer AND subject=NEW.subject) OR person_id=NEW.person_id) BEGIN SELECT RAISE(ABORT,'calls team: refused'); END; CREATE TRIGGER calls_team_home_person_keeps_no_address BEFORE UPDATE OF email ON persons WHEN EXISTS(SELECT 1 FROM calls_team_home_persons WHERE person_id=OLD.id) BEGIN SELECT RAISE(ABORT,'calls team: refused'); END; CREATE TRIGGER calls_team_home_person_keep_row BEFORE DELETE ON persons WHEN EXISTS(SELECT 1 FROM calls_team_home_persons WHERE person_id=OLD.id) BEGIN SELECT RAISE(ABORT,'calls team: refused'); END;