2023-07-29 02:25:56 +00:00
|
|
|
-- Deploy camper:company to pg
|
|
|
|
-- requires: roles
|
|
|
|
-- requires: schema_camper
|
|
|
|
-- requires: extension_vat
|
|
|
|
-- requires: email
|
|
|
|
-- requires: extension_pg_libphonenumber
|
|
|
|
-- requires: extension_uri
|
|
|
|
-- requires: currency_code
|
|
|
|
-- requires: currency
|
|
|
|
-- requires: country_code
|
|
|
|
-- requires: country
|
|
|
|
-- requires: language
|
|
|
|
|
|
|
|
begin;
|
|
|
|
|
|
|
|
set search_path to camper, public;
|
|
|
|
|
|
|
|
create table company (
|
|
|
|
company_id serial primary key,
|
|
|
|
slug uuid not null unique default gen_random_uuid(),
|
|
|
|
business_name text not null constraint business_name_not_empty check (length(trim(business_name)) > 1),
|
|
|
|
vatin vatin not null,
|
|
|
|
trade_name text not null,
|
|
|
|
phone packed_phone_number not null,
|
|
|
|
email email not null,
|
|
|
|
web uri not null,
|
|
|
|
address text not null,
|
|
|
|
city text not null,
|
|
|
|
province text not null,
|
|
|
|
postal_code text not null,
|
|
|
|
country_code country_code not null references country,
|
|
|
|
currency_code currency_code not null references currency,
|
|
|
|
default_lang_tag text not null references language,
|
|
|
|
invoice_number_format text not null default '"FRA"YYYY0000',
|
|
|
|
legal_disclaimer text not null default '',
|
|
|
|
created_at timestamptz not null default current_timestamp
|
|
|
|
);
|
|
|
|
|
Move the user role down to company_user relation
I was starting to add the public page for campsite types, creating more
granular row-level security policies for select, insert, update, and
delete, because now the guest users needed to SELECT them and they have
no related company to filter the rows with. Suddenly, i realized that
the role was wrong in the user relation: a user can be an admin to one
company, and employee to another, and guess to yet another company;
the role should be in the company_user relation instead.
That means that to know the role to set to, the user alone is not enough
and have to know the company as well. Had to change all the
cookie-related function to accept also the company’s host name, as this
is the information that the Go application has.
2023-08-08 00:22:16 +00:00
|
|
|
grant select on table company to guest;
|
|
|
|
grant select on table company to employee;
|
2023-07-29 02:25:56 +00:00
|
|
|
grant select, update on table company to admin;
|
|
|
|
|
|
|
|
commit;
|