2022-07-29 12:37:40 +02:00
|
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
|
--changeset michael.hoennig:test-package-TEST-DATA-GENERATOR 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
|
|
|
|
*/
|
2024-09-23 10:52:37 +02:00
|
|
|
|
create or replace procedure rbactest.package_create_test_data(customerPrefix varchar, pacCount int)
|
2022-07-29 12:37:40 +02:00
|
|
|
|
language plpgsql as $$
|
2022-08-16 10:46:41 +02:00
|
|
|
|
declare
|
2024-09-17 14:21:43 +02:00
|
|
|
|
cust rbactest.customer;
|
2022-08-16 10:46:41 +02:00
|
|
|
|
custAdminUser varchar;
|
|
|
|
|
custAdminRole varchar;
|
|
|
|
|
pacName varchar;
|
2024-09-17 14:21:43 +02:00
|
|
|
|
pac rbactest.package;
|
2022-08-16 10:46:41 +02:00
|
|
|
|
begin
|
2024-09-17 14:21:43 +02:00
|
|
|
|
select * from rbactest.customer where rbactest.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');
|
|
|
|
|
custAdminUser = 'customer-admin@' || cust.prefix || '.example.com';
|
2024-09-17 14:21:43 +02:00
|
|
|
|
custAdminRole = 'rbactest.customer#' || cust.prefix || ':ADMIN';
|
2024-09-16 15:36:37 +02:00
|
|
|
|
call base.defineContext('creating RBAC test package', null, 'superuser-fran@hostsharing.net', custAdminRole);
|
2022-07-29 12:37:40 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
insert
|
2024-09-17 14:21:43 +02:00
|
|
|
|
into rbactest.package (customerUuid, name, description)
|
2022-09-19 20:43:14 +02:00
|
|
|
|
values (cust.uuid, pacName, 'Here you can add your own description of package ' || pacName || '.')
|
2022-08-24 17:56:13 +02:00
|
|
|
|
returning * into pac;
|
2022-07-29 12:37:40 +02:00
|
|
|
|
|
2024-09-16 15:36:37 +02:00
|
|
|
|
call rbac.grantRoleToSubject(
|
2024-09-23 10:52:37 +02:00
|
|
|
|
rbac.getRoleId(rbactest.customer_ADMIN(cust)),
|
|
|
|
|
rbac.findRoleId(rbactest.package_ADMIN(pac)),
|
2024-09-16 15:36:37 +02:00
|
|
|
|
rbac.create_subject('pac-admin-' || pacName || '@' || cust.prefix || '.example.com'),
|
2022-08-24 17:56:13 +02:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2024-09-23 10:52:37 +02:00
|
|
|
|
create or replace procedure rbactest.package_create_test_data()
|
2022-08-24 17:56:13 +02:00
|
|
|
|
language plpgsql as $$
|
|
|
|
|
declare
|
2024-09-17 14:21:43 +02:00
|
|
|
|
cust rbactest.customer;
|
2022-08-24 17:56:13 +02:00
|
|
|
|
begin
|
2024-09-17 14:21:43 +02:00
|
|
|
|
for cust in (select * from rbactest.customer)
|
2022-08-24 17:56:13 +02:00
|
|
|
|
loop
|
|
|
|
|
continue when cust.reference >= 90000; -- reserved for functional testing
|
2024-09-23 10:52:37 +02:00
|
|
|
|
call rbactest.package_create_test_data(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
|
|
|
|
$$;
|
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2024-09-16 15:36:37 +02:00
|
|
|
|
--changeset michael.hoennig:test-package-TEST-DATA-GENERATION –context=dev,tc endDelimiter:--//
|
2022-07-29 12:37:40 +02:00
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
do language plpgsql $$
|
|
|
|
|
begin
|
2024-09-23 10:52:37 +02:00
|
|
|
|
call rbactest.package_create_test_data('xxx', 3);
|
|
|
|
|
call rbactest.package_create_test_data('yyy', 3);
|
|
|
|
|
call rbactest.package_create_test_data('zzz', 3);
|
2022-07-29 12:37:40 +02:00
|
|
|
|
end;
|
|
|
|
|
$$;
|
|
|
|
|
--//
|