Michael Hoennig
2022-10-17 28bdd9220de5eb92ae254e96f364c43b99133c6a
add hs-office-membership test-data
1 files added
3 files modified
61 ■■■■■ changed files
src/main/resources/db/changelog/300-hs-office-membership.sql 1 ●●●● patch | view | raw | blame | history
src/main/resources/db/changelog/303-hs-office-membership-rbac.sql 4 ●●●● patch | view | raw | blame | history
src/main/resources/db/changelog/308-hs-office-membership-test-data.sql 52 ●●●●● patch | view | raw | blame | history
src/main/resources/db/changelog/db.changelog-master.yaml 4 ●●●● patch | view | raw | blame | history
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
src/main/resources/db/changelog/303-hs-office-membership-rbac.sql
@@ -93,7 +93,7 @@
--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 @@
--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
src/main/resources/db/changelog/308-hs-office-membership-test-data.sql
New file
@@ -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;
$$;
--//
src/main/resources/db/changelog/db.changelog-master.yaml
@@ -93,3 +93,7 @@
        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