From 28bdd9220de5eb92ae254e96f364c43b99133c6a Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Mon, 17 Oct 2022 13:23:10 +0200 Subject: [PATCH] add hs-office-membership test-data --- .../db/changelog/300-hs-office-membership.sql | 1 - .../303-hs-office-membership-rbac.sql | 4 +- .../308-hs-office-membership-test-data.sql | 52 +++++++++++++++++++ .../db/changelog/db.changelog-master.yaml | 4 ++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/db/changelog/308-hs-office-membership-test-data.sql diff --git a/src/main/resources/db/changelog/300-hs-office-membership.sql b/src/main/resources/db/changelog/300-hs-office-membership.sql index 12b664b3..d7c04347 100644 --- a/src/main/resources/db/changelog/300-hs-office-membership.sql +++ b/src/main/resources/db/changelog/300-hs-office-membership.sql @@ -6,7 +6,6 @@ CREATE TYPE HsOfficeReasonForTermination AS ENUM ('NONE', 'CANCELLATION', 'TRANSFER', 'DEATH', 'LIQUIDATION', 'EXPULSION'); - CREATE CAST (character varying as HsOfficeReasonForTermination) WITH INOUT AS IMPLICIT; create table if not exists hs_office_membership diff --git a/src/main/resources/db/changelog/303-hs-office-membership-rbac.sql b/src/main/resources/db/changelog/303-hs-office-membership-rbac.sql index 97b1f27f..0671e32d 100644 --- a/src/main/resources/db/changelog/303-hs-office-membership-rbac.sql +++ b/src/main/resources/db/changelog/303-hs-office-membership-rbac.sql @@ -93,7 +93,7 @@ execute procedure hsOfficeMembershipRbacRolesTrigger(); --changeset hs-office-membership-rbac-IDENTITY-VIEW:1 endDelimiter:--// -- ---------------------------------------------------------------------------- call generateRbacIdentityView('hs_office_membership', idNameExpression => $idName$ - (select idName from hs_office_partner_iv p where p.uuid = target.partnerUuid) + target.memberNumber || (select idName from hs_office_partner_iv p where p.uuid = target.partnerUuid) $idName$); --// @@ -102,7 +102,7 @@ call generateRbacIdentityView('hs_office_membership', idNameExpression => $idNam --changeset hs-office-membership-rbac-RESTRICTED-VIEW:1 endDelimiter:--// -- ---------------------------------------------------------------------------- call generateRbacRestrictedView('hs_office_membership', - orderby => 'target.reference', + orderby => 'target.memberNumber', columnUpdates => $updates$ validity = new.validity, reasonForTermination = new.reasonForTermination diff --git a/src/main/resources/db/changelog/308-hs-office-membership-test-data.sql b/src/main/resources/db/changelog/308-hs-office-membership-test-data.sql new file mode 100644 index 00000000..7cffb9ea --- /dev/null +++ b/src/main/resources/db/changelog/308-hs-office-membership-test-data.sql @@ -0,0 +1,52 @@ +--liquibase formatted sql + + +-- ============================================================================ +--changeset hs-office-membership-TEST-DATA-GENERATOR:1 endDelimiter:--// +-- ---------------------------------------------------------------------------- + +/* + Creates a single membership test record. + */ +create or replace procedure createHsOfficeMembershipTestData( forPartnerTradeName varchar, forMainDebitorNumber numeric ) + language plpgsql as $$ +declare + currentTask varchar; + idName varchar; + relatedPartner hs_office_partner; + relatedDebitor hs_office_debitor; + newMemberNumber numeric; +begin + idName := cleanIdentifier( forPartnerTradeName || '#' || forMainDebitorNumber); + currentTask := 'creating SEPA-mandate test-data ' || idName; + call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global.admin'); + execute format('set local hsadminng.currentTask to %L', currentTask); + + select partner.* from hs_office_partner partner + join hs_office_person person on person.uuid = partner.personUuid + where person.tradeName = forPartnerTradeName into relatedPartner; + select d.* from hs_office_debitor d where d.debitorNumber = forMainDebitorNumber into relatedDebitor; + select coalesce(max(memberNumber)+1, 10001) from hs_office_membership into newMemberNumber; + + raise notice 'creating test SEPA-mandate: %', idName; + raise notice '- using partner (%): %', relatedPartner.uuid, relatedPartner; + raise notice '- using debitor (%): %', relatedDebitor.uuid, relatedDebitor; + insert + into hs_office_membership (uuid, partneruuid, maindebitoruuid, membernumber, validity, reasonfortermination) + values (uuid_generate_v4(), relatedPartner.uuid, relatedDebitor.uuid, newMemberNumber, daterange('20221001' , null, '[]'), 'NONE'); +end; $$; +--// + + +-- ============================================================================ +--changeset hs-office-membership-TEST-DATA-GENERATION:1 –context=dev,tc endDelimiter:--// +-- ---------------------------------------------------------------------------- + +do language plpgsql $$ + begin + call createHsOfficeMembershipTestData('First GmbH', 10001); + call createHsOfficeMembershipTestData('Second e.K.', 10002); + call createHsOfficeMembershipTestData('Third OHG', 10003); + end; +$$; +--// diff --git a/src/main/resources/db/changelog/db.changelog-master.yaml b/src/main/resources/db/changelog/db.changelog-master.yaml index be4eff6a..1ecc685d 100644 --- a/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/src/main/resources/db/changelog/db.changelog-master.yaml @@ -93,3 +93,7 @@ databaseChangeLog: file: db/changelog/258-hs-office-sepamandate-test-data.sql - include: file: db/changelog/300-hs-office-membership.sql + - include: + file: db/changelog/303-hs-office-membership-rbac.sql + - include: + file: db/changelog/308-hs-office-membership-test-data.sql