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.
|
|
|
|
|
*/
|
2022-10-14 12:37:59 +02:00
|
|
|
|
create or replace procedure createHsOfficePartnerTestData( personTradeOrFamilyName varchar, contactLabel varchar )
|
2022-09-09 10:40:05 +02:00
|
|
|
|
language plpgsql as $$
|
|
|
|
|
declare
|
|
|
|
|
currentTask varchar;
|
|
|
|
|
idName varchar;
|
2022-09-13 13:27:52 +02:00
|
|
|
|
relatedPerson hs_office_person;
|
|
|
|
|
relatedContact hs_office_contact;
|
2022-10-14 12:37:59 +02:00
|
|
|
|
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
|
|
|
|
insert
|
2022-10-14 12:37:59 +02:00
|
|
|
|
into hs_office_partner (uuid, personuuid, contactuuid, birthday)
|
|
|
|
|
values (uuid_generate_v4(), relatedPerson.uuid, relatedContact.uuid, birthDay);
|
2022-09-09 10:40:05 +02:00
|
|
|
|
end; $$;
|
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Creates a range of test partner for mass data generation.
|
|
|
|
|
*/
|
2022-09-13 13:27:52 +02:00
|
|
|
|
create or replace procedure createHsOfficePartnerTestData(
|
2022-09-09 10:40:05 +02:00
|
|
|
|
startCount integer, -- count of auto generated rows before the run
|
|
|
|
|
endCount integer -- count of auto generated rows after the run
|
|
|
|
|
)
|
|
|
|
|
language plpgsql as $$
|
|
|
|
|
declare
|
2022-09-13 13:27:52 +02:00
|
|
|
|
person hs_office_person;
|
|
|
|
|
contact hs_office_contact;
|
2022-09-09 10:40:05 +02:00
|
|
|
|
begin
|
|
|
|
|
for t in startCount..endCount
|
|
|
|
|
loop
|
2022-09-13 13:27:52 +02:00
|
|
|
|
select p.* from hs_office_person p where tradeName = intToVarChar(t, 4) into person;
|
|
|
|
|
select c.* from hs_office_contact c where c.label = intToVarChar(t, 4) || '#' || t into contact;
|
2022-09-09 10:40:05 +02:00
|
|
|
|
|
2022-09-13 13:27:52 +02:00
|
|
|
|
call createHsOfficePartnerTestData(person.uuid, contact.uuid);
|
2022-09-09 10:40:05 +02:00
|
|
|
|
commit;
|
|
|
|
|
end loop;
|
|
|
|
|
end; $$;
|
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
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
|
2022-09-30 13:11:34 +02:00
|
|
|
|
call createHsOfficePartnerTestData('First GmbH', 'first contact');
|
|
|
|
|
call createHsOfficePartnerTestData('Second e.K.', 'second contact');
|
|
|
|
|
call createHsOfficePartnerTestData('Third OHG', 'third contact');
|
2022-10-03 11:09:36 +02:00
|
|
|
|
call createHsOfficePartnerTestData('Fourth e.G.', 'forth contact');
|
2022-10-14 12:37:59 +02:00
|
|
|
|
call createHsOfficePartnerTestData('Smith', 'fifth contact');
|
2022-09-09 10:40:05 +02:00
|
|
|
|
end;
|
|
|
|
|
$$;
|
|
|
|
|
--//
|