-- Role: role_administrator
-- DROP ROLE IF EXISTS role_administrator;

CREATE ROLE role_owner;


-- Role: role_service
-- DROP ROLE IF EXISTS role_service;

CREATE ROLE role_service;


-- Role: role_maintainer
-- DROP ROLE IF EXISTS role_maintainer;

CREATE ROLE role_maintainer;


-- Role: support_role
-- DROP ROLE IF EXISTS support_role;

CREATE ROLE role_support;


-- User: services
-- DROP USER IF EXISTS services;

CREATE USER service WITH PASSWORD 'password';

-- Assign role to the user
GRANT role_service TO service;


-- User: user_maintainer
-- DROP USER IF EXISTS user_maintainer;

CREATE USER user_maintainer WITH PASSWORD 'password';

-- Assign role to the user
GRANT role_maintainer TO user_maintainer;


-- User: user_support
-- DROP USER IF EXISTS user_support;

CREATE USER user_support WITH PASSWORD 'password';

-- Assign role to the user
GRANT role_support TO user_support;


-- Database: basic_banking
-- DROP DATABASE IF EXISTS basic_banking;

CREATE DATABASE basic_banking
    WITH
    OWNER = role_owner
    ENCODING = 'UTF8'
    TABLESPACE = pg_default
    CONNECTION LIMIT = -1
    IS_TEMPLATE = False;

COMMENT ON DATABASE basic_banking
    IS 'Database for basic banking, registered account and transactions.';
