numerus/deploy/payment_method.sql

36 lines
914 B
PL/PgSQL

-- Deploy numerus:payment_method to pg
-- requires: schema_numerus
-- requires: company
begin;
set search_path to numerus, public;
create table payment_method (
payment_method_id serial primary key,
company_id integer not null references company,
name text not null constraint name_not_empty check(length(trim(name)) > 0),
instructions text not null
);
grant select, insert, update, delete on table payment_method to invoicer;
grant select, insert, update, delete on table payment_method to admin;
grant usage on sequence payment_method_payment_method_id_seq to invoicer;
grant usage on sequence payment_method_payment_method_id_seq to admin;
alter table payment_method enable row level security;
create policy company_policy
on payment_method
using (
exists(
select 1
from company_user
join user_profile using (user_id)
where company_user.company_id = payment_method.company_id
)
);
commit;