cleanup in Liquibase files, header, formatting etc.

This commit is contained in:
Michael Hoennig 2022-07-29 11:38:51 +02:00
parent 4edff1c2f0
commit a478fe4cf1
11 changed files with 124 additions and 45 deletions

View File

@ -9,3 +9,6 @@ spring:
sql: sql:
init: init:
mode: never mode: never
liquibase:
contexts: dev

View File

@ -1,37 +0,0 @@
create table Hostsharing
(
uuid uuid primary key references RbacObject (uuid)
);
create unique index Hostsharing_Singleton on Hostsharing ((0));
insert
into RbacObject (objecttable) values ('hostsharing');
insert
into Hostsharing (uuid) values ((select uuid from RbacObject where objectTable = 'hostsharing'));
create or replace function hostsharingAdmin()
returns RbacRoleDescriptor
returns null on null input
stable leakproof
language sql as $$
select 'global', (select uuid from RbacObject where objectTable = 'hostsharing'), 'admin'::RbacRoleType;
$$;
-- create administrators role with two assigned users
do language plpgsql $$
declare
admins uuid ;
begin
admins = createRole(hostsharingAdmin());
call grantRoleToUser(admins, createRbacUser('mike@hostsharing.net'));
call grantRoleToUser(admins, createRbacUser('sven@hostsharing.net'));
commit;
end;
$$;
begin transaction;
set local hsadminng.currentUser = 'mike@hostsharing.net';
select * from RbacUser where uuid = currentUserId();
end transaction;

View File

@ -1,6 +1,9 @@
--liquibase formatted sql --liquibase formatted sql
--changeset template:1 endDelimiter:--//
-- ============================================================================
--changeset prefix-TEMPLATE:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/* /*

View File

@ -1,7 +1,9 @@
--liquibase formatted sql --liquibase formatted sql
-- ============================================================================
-- LAST-ROW-COUNT
--changeset last-row-count:1 endDelimiter:--// --changeset last-row-count:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/* /*
Returns the row count from the result of the previous query. Returns the row count from the result of the previous query.
Other than the native statement it's usable in an expression. Other than the native statement it's usable in an expression.

View File

@ -1,7 +1,9 @@
--liquibase formatted sql --liquibase formatted sql
-- ============================================================================
-- INT-TO-VAR
--changeset int-to-var:1 endDelimiter:--// --changeset int-to-var:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/* /*
Returns a textual representation of an integer number to be used as generated test data. Returns a textual representation of an integer number to be used as generated test data.

View File

@ -1,7 +1,10 @@
--liquibase formatted sql --liquibase formatted sql
--changeset random-in-range:1 endDelimiter:--//
-- ============================================================================
-- RANDOM-IN-RANGE
--changeset random-in-range:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/* /*
Returns a random integer in the given range (both included), Returns a random integer in the given range (both included),
to be used for test data generation. to be used for test data generation.

View File

@ -1,7 +1,10 @@
--liquibase formatted sql --liquibase formatted sql
--changeset uuid-ossp-extension:1 endDelimiter:--//
-- ============================================================================
-- UUID-OSSP-EXTENSION
--changeset uuid-ossp-extension:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/* /*
Makes improved uuid generation available. Makes improved uuid generation available.
*/ */

View File

@ -639,3 +639,17 @@ begin
return roleIdsToAssume; return roleIdsToAssume;
end; $$; end; $$;
--// --//
-- ============================================================================
-- PGSQL-ROLES
--changeset rbac-base-pgsql-roles:1 endDelimiter:--//
-- ------------------------------------------------------------------
CREATE ROLE admin;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO admin;
CREATE ROLE restricted;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO restricted;
--//

View File

@ -1,10 +1,9 @@
--liquibase formatted sql --liquibase formatted sql
-- ================================================================== -- ============================================================================
-- PERMISSIONS -- PERMISSIONS
--changeset rbac-role-builder-permissions:1 endDelimiter:--// --changeset rbac-role-builder-permissions:1 endDelimiter:--//
-- ------------------------------------------------------------------ -- ----------------------------------------------------------------------------
/* /*
*/ */

View File

@ -0,0 +1,84 @@
--liquibase formatted sql
-- ============================================================================
--changeset hs-base-GLOBAL-OBJECT:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/*
The purpose of this table is to contain a single row
which can be referenced from global roles as an object.
Otherwise these columns needed to be nullable and
many queries would be more complicated.
*/
create table Hostsharing
(
uuid uuid primary key references RbacObject (uuid)
);
create unique index Hostsharing_Singleton on Hostsharing ((0));
/**
A single row to be referenced as a global object.
*/
insert
into RbacObject (objecttable) values ('hostsharing');
insert
into Hostsharing (uuid) values ((select uuid from RbacObject where objectTable = 'hostsharing'));
--//
-- ============================================================================
--changeset hs-base-ADMIN-ROLE:1 endDelimiter:--//
-- ----------------------------------------------------------------------------
/*
A global administrator role.
*/
create or replace function hostsharingAdmin()
returns RbacRoleDescriptor
returns null on null input
stable leakproof
language sql as $$
select 'global', (select uuid from RbacObject where objectTable = 'hostsharing'), 'admin'::RbacRoleType;
$$;
select createRole(hostsharingAdmin());
-- ============================================================================
--changeset hs-base-ADMIN-USERS:1 context:dev endDelimiter:--//
-- ----------------------------------------------------------------------------
/*
Create two users and assign both to the administrators role.
*/
do language plpgsql $$
declare
admins uuid ;
begin
admins = findRoleId(hostsharingAdmin());
call grantRoleToUser(admins, createRbacUser('mike@hostsharing.net'));
call grantRoleToUser(admins, createRbacUser('sven@hostsharing.net'));
end;
$$;
--//
-- ============================================================================
--changeset hs-base-hostsharing-TEST:1 context:dev runAlways:true endDelimiter:--//
-- ----------------------------------------------------------------------------
/*
Tests if currentUserId() can fetch the user from the session variable.
*/
do language plpgsql $$
declare
userName varchar;
begin
set local hsadminng.currentUser = 'mike@hostsharing.net';
select userName from RbacUser where uuid = currentUserId() into userName;
if userName <> 'mike@hostsharing.net' then
raise exception 'fetching initial currentUser failed';
end if;
set local hsadminng.currentUser = 'sven@hostsharing.net';
select userName from RbacUser where uuid = currentUserId() into userName;
if userName <> 'sven@hostsharing.net' then
raise exception 'fetching changed currentUser failed';
end if;
end; $$;
--//

View File

@ -13,4 +13,7 @@ databaseChangeLog:
file: db/changelog/2022-07-28-020-rbac-role-builder.sql file: db/changelog/2022-07-28-020-rbac-role-builder.sql
- include: - include:
file: db/changelog/2022-07-28-030-rbac-statistics.sql file: db/changelog/2022-07-28-030-rbac-statistics.sql
- include:
file: db/changelog/2022-07-29-050-hs-base.sql