2022-09-09 10:40:05 +02:00
|
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
|
--changeset hs-office-partner-TEST-DATA-GENERATOR:1 endDelimiter:--//
|
2022-09-09 10:40:05 +02:00
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Creates a single partner test record.
|
|
|
|
|
*/
|
2024-01-23 15:11:23 +01:00
|
|
|
|
create or replace procedure createHsOfficePartnerTestData(
|
|
|
|
|
debitorNumberPrefix numeric(5),
|
|
|
|
|
personTradeOrFamilyName varchar,
|
|
|
|
|
contactLabel varchar )
|
2022-09-09 10:40:05 +02:00
|
|
|
|
language plpgsql as $$
|
|
|
|
|
declare
|
2022-10-20 20:11:31 +02:00
|
|
|
|
currentTask varchar;
|
|
|
|
|
idName varchar;
|
|
|
|
|
relatedPerson hs_office_person;
|
|
|
|
|
relatedContact hs_office_contact;
|
|
|
|
|
relatedDetailsUuid uuid;
|
|
|
|
|
birthday date;
|
2022-09-09 10:40:05 +02:00
|
|
|
|
begin
|
2022-10-14 12:37:59 +02:00
|
|
|
|
idName := cleanIdentifier( personTradeOrFamilyName|| '-' || contactLabel);
|
2022-10-13 10:36:20 +02:00
|
|
|
|
currentTask := 'creating partner test-data ' || idName;
|
2022-09-14 09:56:22 +02:00
|
|
|
|
call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global.admin');
|
2022-09-09 10:40:05 +02:00
|
|
|
|
execute format('set local hsadminng.currentTask to %L', currentTask);
|
|
|
|
|
|
2022-10-14 12:37:59 +02:00
|
|
|
|
select p.* from hs_office_person p
|
|
|
|
|
where p.tradeName = personTradeOrFamilyName or p.familyName = personTradeOrFamilyName
|
|
|
|
|
into relatedPerson;
|
|
|
|
|
select c.* from hs_office_contact c
|
|
|
|
|
where c.label = contactLabel
|
|
|
|
|
into relatedContact;
|
|
|
|
|
|
|
|
|
|
if relatedPerson.persontype = 'NATURAL' then
|
|
|
|
|
birthday := '1987-10-31'::date;
|
|
|
|
|
end if;
|
2022-09-09 10:40:05 +02:00
|
|
|
|
|
|
|
|
|
raise notice 'creating test partner: %', idName;
|
2022-09-09 17:43:43 +02:00
|
|
|
|
raise notice '- using person (%): %', relatedPerson.uuid, relatedPerson;
|
|
|
|
|
raise notice '- using contact (%): %', relatedContact.uuid, relatedContact;
|
2022-09-09 10:40:05 +02:00
|
|
|
|
|
2022-10-20 20:11:31 +02:00
|
|
|
|
if relatedPerson.persontype = 'NATURAL' then
|
|
|
|
|
insert
|
|
|
|
|
into hs_office_partner_details (uuid, birthName, birthday)
|
|
|
|
|
values (uuid_generate_v4(), 'Meyer', '1987-10-31')
|
|
|
|
|
returning uuid into relatedDetailsUuid;
|
|
|
|
|
else
|
|
|
|
|
insert
|
|
|
|
|
into hs_office_partner_details (uuid, registrationOffice, registrationNumber)
|
|
|
|
|
values (uuid_generate_v4(), 'Hamburg', '12345')
|
|
|
|
|
returning uuid into relatedDetailsUuid;
|
|
|
|
|
end if;
|
2022-09-09 10:40:05 +02:00
|
|
|
|
|
2022-10-20 20:11:31 +02:00
|
|
|
|
insert
|
2024-01-23 15:11:23 +01:00
|
|
|
|
into hs_office_partner (uuid, debitorNumberPrefix, personuuid, contactuuid, detailsUuid)
|
|
|
|
|
values (uuid_generate_v4(), debitorNumberPrefix, relatedPerson.uuid, relatedContact.uuid, relatedDetailsUuid);
|
2022-09-09 10:40:05 +02:00
|
|
|
|
end; $$;
|
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
2022-10-20 20:11:31 +02:00
|
|
|
|
|
2022-09-09 10:40:05 +02:00
|
|
|
|
-- ============================================================================
|
2022-09-13 13:27:52 +02:00
|
|
|
|
--changeset hs-office-partner-TEST-DATA-GENERATION:1 –context=dev,tc endDelimiter:--//
|
2022-09-09 10:40:05 +02:00
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
do language plpgsql $$
|
|
|
|
|
begin
|
2024-01-23 15:11:23 +01:00
|
|
|
|
call createHsOfficePartnerTestData(10001, 'First GmbH', 'first contact');
|
|
|
|
|
call createHsOfficePartnerTestData(10002, 'Second e.K.', 'second contact');
|
|
|
|
|
call createHsOfficePartnerTestData(10003, 'Third OHG', 'third contact');
|
|
|
|
|
call createHsOfficePartnerTestData(10004, 'Fourth e.G.', 'forth contact');
|
|
|
|
|
call createHsOfficePartnerTestData(10010, 'Smith', 'fifth contact');
|
2022-09-09 10:40:05 +02:00
|
|
|
|
end;
|
|
|
|
|
$$;
|
|
|
|
|
--//
|