numerus/deploy/quote_number_counter.sql

34 lines
856 B
MySQL
Raw Permalink Normal View History

-- Deploy numerus:quote_number_counter to pg
-- requires: roles
-- requires: schema_numerus
-- requires: company
begin;
set search_path to numerus, public;
create table quote_number_counter (
company_id integer not null references company,
year integer not null constraint year_always_positive check(year > 0),
currval integer not null constraint counter_zero_or_positive check(currval >= 0),
primary key (company_id, year)
);
grant select, insert, update on table quote_number_counter to invoicer;
grant select, insert, update on table quote_number_counter to admin;
alter table quote_number_counter enable row level security;
create policy company_policy
on quote_number_counter
using (
exists(
select 1
from company_user
join user_profile using (user_id)
where company_user.company_id = quote_number_counter.company_id
)
);
commit;