hs.hsadmin.ng/src/main/resources/db/changelog/5-hs-office/501-contact/5018-hs-office-contact-test-data.sql

76 lines
2.7 KiB
MySQL
Raw Normal View History

--liquibase formatted sql
-- ============================================================================
2024-09-16 09:00:18 +02:00
--changeset michael.hoennig:hs-office-contact-TEST-DATA-GENERATOR endDelimiter:--//
-- ----------------------------------------------------------------------------
/*
Creates a single contact test record.
*/
create or replace procedure createHsOfficeContactTestData(contCaption varchar)
language plpgsql as $$
declare
postalAddr varchar;
emailAddr varchar;
begin
2024-09-14 10:34:11 +02:00
emailAddr = 'contact-admin@' || base.cleanIdentifier(contCaption) || '.example.com';
2024-09-13 20:21:12 +02:00
call base.defineContext('creating contact test-data');
perform rbac.create_subject(emailAddr);
2024-09-13 20:21:12 +02:00
call base.defineContext('creating contact test-data', null, emailAddr);
postalAddr := E'Vorname Nachname\nStraße Hnr\nPLZ Stadt';
raise notice 'creating test contact: %', contCaption;
insert
into hs_office_contact (caption, postaladdress, emailaddresses, phonenumbers)
values (
contCaption,
postalAddr,
('{ "main": "' || emailAddr || '" }')::jsonb,
('{ "phone_office": "+49 123 1234567" }')::jsonb
);
end; $$;
--//
/*
Creates a range of test contact for mass data generation.
*/
create or replace procedure createHsOfficeContactTestData(
startCount integer, -- count of auto generated rows before the run
endCount integer -- count of auto generated rows after the run
)
language plpgsql as $$
begin
for t in startCount..endCount
loop
2024-09-13 20:21:12 +02:00
call createHsOfficeContactTestData(base.intToVarChar(t, 4) || '#' || t);
commit;
end loop;
end; $$;
--//
-- ============================================================================
2024-09-16 09:00:18 +02:00
--changeset michael.hoennig:hs-office-contact-TEST-DATA-GENERATION context=dev,tc endDelimiter:--//
-- ----------------------------------------------------------------------------
do language plpgsql $$
begin
-- TODO: use better names
call createHsOfficeContactTestData('first contact');
call createHsOfficeContactTestData('second contact');
call createHsOfficeContactTestData('third contact');
call createHsOfficeContactTestData('fourth contact');
call createHsOfficeContactTestData('fifth contact');
call createHsOfficeContactTestData('sixth contact');
call createHsOfficeContactTestData('seventh contact');
call createHsOfficeContactTestData('eighth contact');
call createHsOfficeContactTestData('ninth contact');
call createHsOfficeContactTestData('tenth contact');
call createHsOfficeContactTestData('eleventh contact');
call createHsOfficeContactTestData('twelfth contact');
end;
$$;
--//