2022-07-29 12:37:40 +02:00
|
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
|
|
|
|
--changeset hs-package-TEST-DATA-GENERATOR:1 endDelimiter:--//
|
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
/*
|
2022-08-24 17:56:13 +02:00
|
|
|
|
Creates the given number of test packages for the given customer.
|
2022-07-29 12:37:40 +02:00
|
|
|
|
*/
|
2022-08-24 17:56:13 +02:00
|
|
|
|
create or replace procedure createPackageTestData(customerPrefix varchar, pacCount int)
|
2022-07-29 12:37:40 +02:00
|
|
|
|
language plpgsql as $$
|
2022-08-16 10:46:41 +02:00
|
|
|
|
declare
|
|
|
|
|
cust customer;
|
|
|
|
|
custAdminUser varchar;
|
|
|
|
|
custAdminRole varchar;
|
|
|
|
|
pacName varchar;
|
|
|
|
|
currentTask varchar;
|
|
|
|
|
pac package;
|
|
|
|
|
begin
|
2022-08-24 17:56:13 +02:00
|
|
|
|
select * from customer where customer.prefix = customerPrefix into cust;
|
2022-07-29 12:37:40 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
for t in 0..(pacCount-1)
|
2022-08-16 10:46:41 +02:00
|
|
|
|
loop
|
2022-08-24 17:56:13 +02:00
|
|
|
|
pacName = cust.prefix || to_char(t, 'fm00');
|
|
|
|
|
currentTask = 'creating RBAC test package #' || pacName || ' for customer ' || cust.prefix || ' #' ||
|
|
|
|
|
cust.uuid;
|
|
|
|
|
|
|
|
|
|
custAdminUser = 'customer-admin@' || cust.prefix || '.example.com';
|
|
|
|
|
custAdminRole = 'customer#' || cust.prefix || '.admin';
|
2022-08-30 09:35:59 +02:00
|
|
|
|
call defineContext(currentTask, null, custAdminUser, custAdminRole);
|
2022-08-24 17:56:13 +02:00
|
|
|
|
raise notice 'task: % by % as %', currentTask, custAdminUser, custAdminRole;
|
2022-07-29 12:37:40 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
insert
|
|
|
|
|
into package (customerUuid, name, description)
|
|
|
|
|
values (cust.uuid, pacName, 'Here can add your own description of package ' || pacName || '.')
|
|
|
|
|
returning * into pac;
|
2022-07-29 12:37:40 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
call grantRoleToUser(
|
|
|
|
|
getRoleId(customerAdmin(cust), 'fail'),
|
|
|
|
|
findRoleId(packageAdmin(pac)),
|
|
|
|
|
createRbacUser('pac-admin-' || pacName || '@' || cust.prefix || '.example.com'),
|
|
|
|
|
true);
|
2022-07-29 12:37:40 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
end loop;
|
|
|
|
|
end; $$;
|
2022-08-05 14:31:54 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
/*
|
|
|
|
|
Creates a range of test packages for mass data generation.
|
|
|
|
|
*/
|
|
|
|
|
create or replace procedure createPackageTestData()
|
|
|
|
|
language plpgsql as $$
|
|
|
|
|
declare
|
|
|
|
|
cust customer;
|
|
|
|
|
begin
|
|
|
|
|
for cust in (select * from customer)
|
|
|
|
|
loop
|
|
|
|
|
continue when cust.reference >= 90000; -- reserved for functional testing
|
|
|
|
|
call createPackageTestData(cust.prefix, 3);
|
2022-08-16 10:46:41 +02:00
|
|
|
|
end loop;
|
2022-07-29 12:37:40 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
commit;
|
2022-08-16 10:46:41 +02:00
|
|
|
|
end ;
|
2022-07-29 12:37:40 +02:00
|
|
|
|
$$;
|
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
|
|
|
|
--changeset hs-package-TEST-DATA-GENERATION:1 –context=dev,tc endDelimiter:--//
|
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
do language plpgsql $$
|
|
|
|
|
begin
|
2022-08-24 17:56:13 +02:00
|
|
|
|
call createPackageTestData('xxx', 3);
|
|
|
|
|
call createPackageTestData('yyy', 3);
|
|
|
|
|
call createPackageTestData('zzz', 3);
|
2022-07-29 12:37:40 +02:00
|
|
|
|
end;
|
|
|
|
|
$$;
|
|
|
|
|
--//
|