39 lines
930 B
PL/PgSQL
39 lines
930 B
PL/PgSQL
-- Deploy camper:campsite_type to pg
|
|
-- requires: roles
|
|
-- requires: schema_camper
|
|
-- requires: company
|
|
|
|
begin;
|
|
|
|
set search_path to camper, public;
|
|
|
|
create table campsite_type (
|
|
campsite_type_id serial primary key,
|
|
company_id integer not null references company,
|
|
slug uuid not null unique default gen_random_uuid(),
|
|
name text not null constraint name_not_empty check(length(trim(name)) > 0),
|
|
description xml not null default ''::xml,
|
|
active boolean not null default true
|
|
);
|
|
|
|
grant select on table campsite_type to employee;
|
|
grant select, insert, update, delete on table campsite_type to admin;
|
|
|
|
grant usage on sequence campsite_type_campsite_type_id_seq to admin;
|
|
|
|
alter table campsite_type enable row level security;
|
|
|
|
create policy company_policy
|
|
on campsite_type
|
|
using (
|
|
exists(
|
|
select 1
|
|
from company_user
|
|
join user_profile using (user_id)
|
|
where company_user.company_id = campsite_type.company_id
|
|
)
|
|
);
|
|
|
|
|
|
commit;
|