-- Schema and table definitions for faktura
--
-- SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri
-- SPDX-FileCopyrightText: 2024 Harald Eilertsen
--
-- SPDX-License-Identifier: AGPL-3.0-or-later

create schema api;

create table api.clients (
  id serial primary key,
  name text not null,
  contact text,
  email text not null,
  phone text,
  address text,
  vat boolean
);

-- Set up web user for anonymous requests
create role web_anon nologin;
grant usage on schema api to web_anon;
grant select on api.clients to web_anon;

-- Set up trusted user for modifications
create role faktura_user nologin;
grant usage on schema api to faktura_user;
grant all on api.clients to faktura_user;
grant usage, select on sequence api.clients_id_seq to faktura_user;

-- Set up authenticator user for db login
create role authenticator noinherit login password 'password';
grant web_anon to authenticator;
grant faktura_user to authenticator;
