-- Deploy camper:contact_email to pg
-- requires: roles
-- requires: schema_camper
-- requires: email
-- requires: contact

begin;

set search_path to camper, public;

create table contact_email (
	contact_id integer primary key references contact,
	email email not null
);

grant select, insert, update, delete on table contact_email to employee;
grant select, insert, update, delete on table contact_email to admin;

alter table contact_email enable row level security;

create policy company_policy
on contact_email
using (
	exists(
		select 1
		from contact
		where contact.contact_id = contact_email.contact_id
	)
);

commit;
