2022-07-29 12:14:22 +02:00
|
|
|
|
--liquibase formatted sql
|
|
|
|
|
|
|
|
|
|
|
2022-07-29 11:39:32 +02:00
|
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
|
--changeset test-customer-TEST-DATA-GENERATOR:1 endDelimiter:--//
|
2022-07-29 11:39:32 +02:00
|
|
|
|
-- ----------------------------------------------------------------------------
|
2022-07-29 12:14:22 +02:00
|
|
|
|
/*
|
|
|
|
|
Generates a customer reference number for a given test data counter.
|
|
|
|
|
*/
|
|
|
|
|
create or replace function testCustomerReference(customerCount integer)
|
|
|
|
|
returns integer
|
|
|
|
|
returns null on null input
|
|
|
|
|
language plpgsql as $$
|
|
|
|
|
begin
|
|
|
|
|
return 10000 + customerCount;
|
|
|
|
|
end; $$;
|
2022-07-29 11:39:32 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
|
2022-07-29 12:14:22 +02:00
|
|
|
|
/*
|
2022-08-24 17:56:13 +02:00
|
|
|
|
Creates a single customer test record with dist.
|
2022-07-29 12:14:22 +02:00
|
|
|
|
*/
|
2022-08-31 09:42:40 +02:00
|
|
|
|
create or replace procedure createTestCustomerTestData(
|
2022-08-24 17:56:13 +02:00
|
|
|
|
custReference integer,
|
|
|
|
|
custPrefix varchar
|
2022-07-29 11:39:32 +02:00
|
|
|
|
)
|
|
|
|
|
language plpgsql as $$
|
|
|
|
|
declare
|
|
|
|
|
custRowId uuid;
|
|
|
|
|
custAdminName varchar;
|
2024-03-11 12:30:43 +01:00
|
|
|
|
custAdminUuid uuid;
|
|
|
|
|
newCust test_customer;
|
2022-07-29 11:39:32 +02:00
|
|
|
|
begin
|
2022-08-24 17:56:13 +02:00
|
|
|
|
custRowId = uuid_generate_v4();
|
|
|
|
|
custAdminName = 'customer-admin@' || custPrefix || '.example.com';
|
2024-09-13 12:44:56 +02:00
|
|
|
|
custAdminUuid = rbac.create_subject(custAdminName);
|
2022-07-29 11:39:32 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
insert
|
2022-08-31 09:42:40 +02:00
|
|
|
|
into test_customer (reference, prefix, adminUserName)
|
2022-08-24 17:56:13 +02:00
|
|
|
|
values (custReference, custPrefix, custAdminName);
|
2024-03-11 12:30:43 +01:00
|
|
|
|
|
|
|
|
|
select * into newCust
|
|
|
|
|
from test_customer where reference=custReference;
|
2024-09-13 16:20:14 +02:00
|
|
|
|
call rbac.grantRoleToSubject(
|
2024-03-11 12:30:43 +01:00
|
|
|
|
getRoleId(testCustomerOwner(newCust)),
|
|
|
|
|
getRoleId(testCustomerAdmin(newCust)),
|
|
|
|
|
custAdminUuid,
|
|
|
|
|
true);
|
2022-08-24 17:56:13 +02:00
|
|
|
|
end; $$;
|
|
|
|
|
--//
|
2022-07-29 11:39:32 +02:00
|
|
|
|
|
2022-08-24 17:56:13 +02:00
|
|
|
|
/*
|
|
|
|
|
Creates a range of test customers for mass data generation.
|
|
|
|
|
*/
|
2022-08-31 09:42:40 +02:00
|
|
|
|
create or replace procedure createTestCustomerTestData(
|
2022-08-24 17:56:13 +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 $$
|
|
|
|
|
begin
|
|
|
|
|
for t in startCount..endCount
|
|
|
|
|
loop
|
2024-09-13 08:08:19 +02:00
|
|
|
|
call createTestCustomerTestData(testCustomerReference(t), basis.intToVarChar(t, 3));
|
2022-08-24 17:56:13 +02:00
|
|
|
|
commit;
|
2022-07-29 11:39:32 +02:00
|
|
|
|
end loop;
|
|
|
|
|
end; $$;
|
|
|
|
|
--//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- ============================================================================
|
2022-08-31 09:42:40 +02:00
|
|
|
|
--changeset test-customer-TEST-DATA-GENERATION:1 –context=dev,tc endDelimiter:--//
|
2022-07-29 11:39:32 +02:00
|
|
|
|
-- ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
do language plpgsql $$
|
|
|
|
|
begin
|
2024-09-13 20:11:34 +02:00
|
|
|
|
call basis.defineContext('creating RBAC test customer', null, 'superuser-alex@hostsharing.net', 'rbac.global#global:ADMIN');
|
2024-08-29 17:00:19 +02:00
|
|
|
|
|
2022-08-31 09:42:40 +02:00
|
|
|
|
call createTestCustomerTestData(99901, 'xxx');
|
|
|
|
|
call createTestCustomerTestData(99902, 'yyy');
|
|
|
|
|
call createTestCustomerTestData(99903, 'zzz');
|
2022-07-29 11:39:32 +02:00
|
|
|
|
end;
|
|
|
|
|
$$;
|
|
|
|
|
--//
|