From 210e29bc82fb439a50d1ac8016aa6d6440c66f52 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 18 Sep 2024 06:24:47 +0200 Subject: [PATCH] introduce separate database-schema for hs-office and amend generators - tests green --- .../hsadminng/rbac/generator/InsertTriggerGenerator.java | 4 ++-- src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql | 2 +- .../201-rbactest-customer/2013-rbactest-customer-rbac.sql | 2 +- .../5-hs-office/504-partner/5040-hs-office-partner.sql | 6 +++--- .../504-partner/5043-hs-office-partner-rbac.sql | 2 +- .../504-partner/5044-hs-office-partner-details-rbac.sql | 2 +- .../5-hs-office/506-debitor/5060-hs-office-debitor.sql | 8 ++++---- .../506-debitor/5063-hs-office-debitor-rbac.sql | 2 +- .../510-membership/5103-hs-office-membership-rbac.sql | 2 +- .../511-coopshares/5110-hs-office-coopshares.sql | 4 ++-- .../512-coopassets/5120-hs-office-coopassets.sql | 4 ++-- .../630-booking-item/6303-hs-booking-item-rbac.sql | 2 +- .../debitor/HsOfficeDebitorRepositoryIntegrationTest.java | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java index c5bc51c4..5c398da2 100644 --- a/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java +++ b/src/main/java/net/hostsharing/hsadminng/rbac/generator/InsertTriggerGenerator.java @@ -213,7 +213,7 @@ public class InsertTriggerGenerator { if (g.getSuperRoleDef().isGlobal(GUEST)) { plPgSql.writeLn( """ - -- check INSERT INSERT permission for rbac.global anyone + -- check INSERT permission for rbac.global anyone if ${caseCondition}true then return NEW; end if; @@ -222,7 +222,7 @@ public class InsertTriggerGenerator { } else if (g.getSuperRoleDef().isGlobal(ADMIN)) { plPgSql.writeLn( """ - -- check INSERT INSERT if rbac.global ADMIN + -- check INSERT permission if rbac.global ADMIN if ${caseCondition}rbac.isGlobalAdmin() then return NEW; end if; diff --git a/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql b/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql index b2e73ca1..6a403e08 100644 --- a/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql +++ b/src/main/resources/db/changelog/1-rbac/1050-rbac-base.sql @@ -384,7 +384,7 @@ create index on rbac.permission (objectUuid, op); create index on rbac.permission (opTableName, op); ALTER TABLE rbac.permission - ADD CONSTRAINT RbacPermission_uc UNIQUE NULLS NOT DISTINCT (objectUuid, op, opTableName); + ADD CONSTRAINT unique_including_null_values UNIQUE NULLS NOT DISTINCT (objectUuid, op, opTableName); call base.create_journal('rbac.permission'); diff --git a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql index 1f35407a..9857457b 100644 --- a/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql +++ b/src/main/resources/db/changelog/2-rbactest/201-rbactest-customer/2013-rbactest-customer-rbac.sql @@ -137,7 +137,7 @@ create or replace function rbactest.customer_insert_permission_check_tf() declare superObjectUuid uuid; begin - -- check INSERT INSERT if rbac.global ADMIN + -- check INSERT permission if rbac.global ADMIN if rbac.isGlobalAdmin() then return NEW; end if; diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql index 81a817ec..f696d310 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5040-hs-office-partner.sql @@ -48,7 +48,7 @@ create table hs_office.partner /** Trigger function to delete related details of a partner to delete. */ -create or replace function deleteHsOfficeDependentsOnPartnerDelete() +create or replace function hs_office.partner_delete_dependents_tf() returns trigger language PLPGSQL as $$ @@ -73,11 +73,11 @@ end; $$; /** Triggers deletion of related rows of a partner to delete. */ -create trigger hs_office.partner_delete_dependents_trigger +create trigger delete_dependents_tg after delete on hs_office.partner for each row - execute procedure deleteHsOfficeDependentsOnPartnerDelete(); + execute procedure hs_office.partner_delete_dependents_tf(); -- ============================================================================ --changeset michael.hoennig:hs-office-partner-MAIN-TABLE-JOURNAL endDelimiter:--// diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql index adcfdad2..5f9c6284 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5043-hs-office-partner-rbac.sql @@ -214,7 +214,7 @@ create or replace function hs_office.partner_insert_permission_check_tf() declare superObjectUuid uuid; begin - -- check INSERT INSERT if rbac.global ADMIN + -- check INSERT permission if rbac.global ADMIN if rbac.isGlobalAdmin() then return NEW; end if; diff --git a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql index 554fc07c..8dc4454e 100644 --- a/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/504-partner/5044-hs-office-partner-details-rbac.sql @@ -118,7 +118,7 @@ create or replace function hs_office.partner_details_insert_permission_check_tf( declare superObjectUuid uuid; begin - -- check INSERT INSERT if rbac.global ADMIN + -- check INSERT permission if rbac.global ADMIN if rbac.isGlobalAdmin() then return NEW; end if; diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql index 928d69e2..f9639533 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5060-hs-office-debitor.sql @@ -29,9 +29,9 @@ create table hs_office.debitor -- ---------------------------------------------------------------------------- /** - Trigger function to delete related rows of a debitor to delete. + Trigger function to delete related relations of a debitor to delete. */ -create or replace function deleteHsOfficeDependentsOnDebitorDelete() +create or replace function hs_office.debitor_delete_dependents_tf() returns trigger language PLPGSQL as $$ @@ -50,11 +50,11 @@ end; $$; /** Triggers deletion of related details of a debitor to delete. */ -create trigger hs_office.debitor_delete_dependents_trigger +create trigger debitor_delete_dependents_tg after delete on hs_office.debitor for each row -execute procedure deleteHsOfficeDependentsOnDebitorDelete(); +execute procedure hs_office.debitor_delete_dependents_tf(); -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql index 15a31518..2b1756f0 100644 --- a/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/506-debitor/5063-hs-office-debitor-rbac.sql @@ -187,7 +187,7 @@ create or replace function hs_office.debitor_insert_permission_check_tf() declare superObjectUuid uuid; begin - -- check INSERT INSERT if rbac.global ADMIN + -- check INSERT permission if rbac.global ADMIN if rbac.isGlobalAdmin() then return NEW; end if; diff --git a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql index 5d636e65..e5d6fa16 100644 --- a/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql +++ b/src/main/resources/db/changelog/5-hs-office/510-membership/5103-hs-office-membership-rbac.sql @@ -149,7 +149,7 @@ create or replace function hs_office.membership_insert_permission_check_tf() declare superObjectUuid uuid; begin - -- check INSERT INSERT if rbac.global ADMIN + -- check INSERT permission if rbac.global ADMIN if rbac.isGlobalAdmin() then return NEW; end if; diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql index 4d9e906e..7e15a874 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql @@ -27,7 +27,7 @@ create table if not exists hs_office.coopsharestransaction -- ---------------------------------------------------------------------------- alter table hs_office.coopsharestransaction - add constraint hs_office.coopsharestransaction_reverse_entry_missing + add constraint reverse_entry_missing check ( transactionType = 'ADJUSTMENT' and adjustedShareTxUuid is not null or transactionType <> 'ADJUSTMENT' and adjustedShareTxUuid is null); --// @@ -55,7 +55,7 @@ begin end; $$; alter table hs_office.coopsharestransaction - add constraint hs_office.coopshares_positive + add constraint check_positive_total_shares_count check ( checkSharesByMembershipUuid(membershipUuid, shareCount) ); --// diff --git a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql index d0838330..4804f4d7 100644 --- a/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql +++ b/src/main/resources/db/changelog/5-hs-office/512-coopassets/5120-hs-office-coopassets.sql @@ -35,7 +35,7 @@ create table if not exists hs_office.coopassetstransaction -- ---------------------------------------------------------------------------- alter table hs_office.coopassetstransaction - add constraint hs_office.coopassetstransaction_reverse_entry_missing + add constraint reverse_entry_missing check ( transactionType = 'ADJUSTMENT' and adjustedAssetTxUuid is not null or transactionType <> 'ADJUSTMENT' and adjustedAssetTxUuid is null); --// @@ -63,7 +63,7 @@ begin end; $$; alter table hs_office.coopassetstransaction - add constraint hs_office.coopassets_positive + add constraint check_positive_total check ( checkAssetsByMembershipUuid(membershipUuid, assetValue) ); --// diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql index 40512aef..cf6a9560 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6303-hs-booking-item-rbac.sql @@ -225,7 +225,7 @@ create or replace function hs_booking_item_insert_permission_check_tf() declare superObjectUuid uuid; begin - -- check INSERT INSERT if rbac.global ADMIN + -- check INSERT permission if rbac.global ADMIN if rbac.isGlobalAdmin() then return NEW; end if; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java index 4f00c0ef..53807d89 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepositoryIntegrationTest.java @@ -141,7 +141,7 @@ class HsOfficeDebitorRepositoryIntegrationTest extends ContextBasedTestWithClean // then result.assertExceptionWithRootCauseMessage(org.hibernate.exception.ConstraintViolationException.class, - "ERROR: new row for relation \"hs_office.debitor\" violates check constraint \"check_default_prefix\""); + "ERROR: new row for relation \"debitor\" violates check constraint \"check_default_prefix\""); } @Test