2022-07-29 12:37:40 +02:00
|
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
|
--changeset test-package-TEST-DATA-GENERATOR:1 endDelimiter:--//
|
2022-07-29 12:37:40 +02:00
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
/*
|
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
|
2022-08-31 09:42:40 +02:00
|
|
|
|
cust test_customer;
|
2022-08-16 10:46:41 +02:00
|
|
|
|
custAdminUser varchar;
|
|
|
|
|
custAdminRole varchar;
|
|
|
|
|
pacName varchar;
|
|
|
|
|
currentTask varchar;
|
2022-08-31 09:42:40 +02:00
|
|
|
|
pac test_package;
|
2022-08-16 10:46:41 +02:00
|
|
|
|
begin
|
2022-08-31 09:42:40 +02:00
|
|
|
|
select * from test_customer where test_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';
|
2022-08-31 09:42:40 +02:00
|
|
|
|
custAdminRole = 'test_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
|
2022-08-31 09:42:40 +02:00
|
|
|
|
into test_package (customerUuid, name, description)
|
2022-08-24 17:56:13 +02:00
|
|
|
|
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(
|
2022-08-31 09:42:40 +02:00
|
|
|
|
getRoleId(testCustomerAdmin(cust), 'fail'),
|
|
|
|
|
findRoleId(testPackageAdmin(pac)),
|
2022-08-24 17:56:13 +02:00
|
|
|
|
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
|
2022-08-31 09:42:40 +02:00
|
|
|
|
cust test_customer;
|
2022-08-24 17:56:13 +02:00
|
|
|
|
begin
|
2022-08-31 09:42:40 +02:00
|
|
|
|
for cust in (select * from test_customer)
|
2022-08-24 17:56:13 +02:00
|
|
|
|
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
|
|
|
|
$$;
|
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
|
--changeset test-package-TEST-DATA-GENERATION:1 –context=dev,tc endDelimiter:--//
|
2022-07-29 12:37:40 +02:00
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
$$;
|
|
|
|
|
--//
|