2023-02-09 10:42:31 +00:00
|
|
|
-- Deploy numerus:invoice to pg
|
|
|
|
-- requires: schema_numerus
|
|
|
|
-- requires: company
|
|
|
|
-- requires: contact
|
|
|
|
-- requires: invoice_status
|
|
|
|
-- requires: currency
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to numerus, public;
|
|
|
|
|
|
|
|
create table invoice (
|
|
|
|
invoice_id serial primary key,
|
|
|
|
company_id integer not null references company,
|
|
|
|
slug uuid not null unique default gen_random_uuid(),
|
2023-02-17 11:39:32 +00:00
|
|
|
invoice_number text not null constraint invoice_number_not_empty check(length(trim(invoice_number)) > 1),
|
2023-02-09 10:42:31 +00:00
|
|
|
invoice_date date not null default current_date,
|
|
|
|
contact_id integer not null references contact,
|
|
|
|
invoice_status text not null default 'created' references invoice_status,
|
|
|
|
notes text not null default '',
|
2023-03-05 17:50:57 +00:00
|
|
|
payment_method_id integer not null references payment_method,
|
2023-02-09 10:42:31 +00:00
|
|
|
currency_code text not null references currency,
|
|
|
|
created_at timestamptz not null default current_timestamp
|
|
|
|
);
|
|
|
|
|
|
|
|
grant select, insert, update, delete on table invoice to invoicer;
|
|
|
|
grant select, insert, update, delete on table invoice to admin;
|
|
|
|
|
|
|
|
grant usage on sequence invoice_invoice_id_seq to invoicer;
|
|
|
|
grant usage on sequence invoice_invoice_id_seq to admin;
|
|
|
|
|
|
|
|
alter table invoice enable row level security;
|
|
|
|
|
|
|
|
create policy company_policy
|
|
|
|
on invoice
|
|
|
|
using (
|
|
|
|
exists(
|
|
|
|
select 1
|
|
|
|
from company_user
|
|
|
|
join user_profile using (user_id)
|
|
|
|
where company_user.company_id = invoice.company_id
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
commit;
|