-- Deploy numerus:payment_attachment to pg
-- requires: roles
-- requires: schema_numerus
-- requires: payment

begin;

set search_path to numerus, public;

create table payment_attachment (
	payment_id integer primary key references payment,
	original_filename text not null,
	mime_type text not null,
	content bytea not null
);

grant select, insert, update, delete on table payment_attachment to invoicer;
grant select, insert, update, delete on table payment_attachment to admin;

alter table payment_attachment enable row level security;

create policy company_policy
on payment_attachment
using (
	exists(
		select 1
		from payment
		where payment.payment_id = payment_attachment.payment_id
	)
);


commit;
