numerus/deploy/product.sql
jordi fita mas e9cc331ee0 Add products section
There is still some issues with the price field, because for now it is
in cents, but do not have time now to fix that.
2023-02-04 11:32:39 +01:00

43 lines
1011 B
PL/PgSQL

-- Deploy numerus:product to pg
-- requires: schema_numerus
-- requires: company
begin;
set search_path to numerus, public;
create table product (
product_id serial primary key,
company_id integer not null references company,
slug uuid not null default gen_random_uuid(),
name text not null,
description text not null,
price integer not null,
tax_id integer not null references tax,
created_at timestamptz not null default current_timestamp
);
comment on column product.price is
'Price is stored in cents.';
grant select, insert, update, delete on table product to invoicer;
grant select, insert, update, delete on table product to admin;
grant usage on sequence product_product_id_seq to invoicer;
grant usage on sequence product_product_id_seq to admin;
alter table product enable row level security;
create policy company_policy
on product
using (
exists(
select 1
from company_user
join user_profile using (user_id)
where company_user.company_id = product.company_id
)
);
commit;