initial data import for hs-office tables (db-migration #10)
Co-authored-by: Michael Hoennig <michael@hoennig.de> Co-authored-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net> Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/10 Reviewed-by: Timotheus Pokorra <timotheus.pokorra@hostsharing.net>
This commit is contained in:
18
src/main/resources/db/changelog/009-check-environment.sql
Normal file
18
src/main/resources/db/changelog/009-check-environment.sql
Normal file
@ -0,0 +1,18 @@
|
||||
--liquibase formatted sql
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- NUMERIC-HASH-FUNCTIONS
|
||||
--changeset hash:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
do $$
|
||||
begin
|
||||
if starts_with ('${HSADMINNG_POSTGRES_ADMIN_USERNAME}', '$') then
|
||||
RAISE EXCEPTION 'environment variable HSADMINNG_POSTGRES_ADMIN_USERNAME not set';
|
||||
end if;
|
||||
if starts_with ('${HSADMINNG_POSTGRES_RESTRICTED_USERNAME}', '$') then
|
||||
RAISE EXCEPTION 'environment variable HSADMINNG_POSTGRES_RESTRICTED_USERNAME not set';
|
||||
end if;
|
||||
end $$
|
||||
--//
|
@ -55,7 +55,7 @@ end; $$;
|
||||
*/
|
||||
create or replace function currentTask()
|
||||
returns varchar(96)
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentTask varchar(96);
|
||||
@ -83,7 +83,7 @@ end; $$;
|
||||
*/
|
||||
create or replace function currentRequest()
|
||||
returns varchar(512)
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentRequest varchar(512);
|
||||
@ -107,7 +107,7 @@ end; $$;
|
||||
*/
|
||||
create or replace function currentUser()
|
||||
returns varchar(63)
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentUser varchar(63);
|
||||
@ -131,7 +131,7 @@ end; $$;
|
||||
*/
|
||||
create or replace function assumedRoles()
|
||||
returns varchar(63)[]
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentSubject varchar(63);
|
||||
@ -155,7 +155,7 @@ create or replace function cleanIdentifier(rawIdentifier varchar)
|
||||
declare
|
||||
cleanIdentifier varchar;
|
||||
begin
|
||||
cleanIdentifier := regexp_replace(rawIdentifier, '[^A-Za-z0-9\-._]+', '', 'g');
|
||||
cleanIdentifier := regexp_replace(rawIdentifier, '[^A-Za-z0-9\-._:]+', '', 'g');
|
||||
return cleanIdentifier;
|
||||
end; $$;
|
||||
|
||||
@ -214,7 +214,7 @@ end ; $$;
|
||||
|
||||
create or replace function currentSubjects()
|
||||
returns varchar(63)[]
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
assumedRoles varchar(63)[];
|
||||
@ -229,7 +229,7 @@ end; $$;
|
||||
|
||||
create or replace function hasAssumedRole()
|
||||
returns boolean
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
begin
|
||||
return array_length(assumedRoles(), 1) > 0;
|
||||
|
@ -208,7 +208,7 @@ create type RbacRoleDescriptor as
|
||||
create or replace function roleDescriptor(objectTable varchar(63), objectUuid uuid, roleType RbacRoleType)
|
||||
returns RbacRoleDescriptor
|
||||
returns null on null input
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language sql as $$
|
||||
select objectTable, objectUuid, roleType::RbacRoleType;
|
||||
$$;
|
||||
@ -432,7 +432,7 @@ $$;
|
||||
create or replace function findPermissionId(forObjectUuid uuid, forOp RbacOp)
|
||||
returns uuid
|
||||
returns null on null input
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language sql as $$
|
||||
select uuid
|
||||
from RbacPermission p
|
||||
@ -515,7 +515,7 @@ end; $$;
|
||||
|
||||
create or replace function isPermissionGrantedToSubject(permissionId uuid, subjectId uuid)
|
||||
returns BOOL
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language sql as $$
|
||||
select exists(
|
||||
select *
|
||||
@ -537,7 +537,7 @@ $$;
|
||||
|
||||
create or replace function hasGlobalRoleGranted(userUuid uuid)
|
||||
returns bool
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language sql as $$
|
||||
select exists(
|
||||
select r.uuid
|
||||
@ -758,13 +758,20 @@ $$;
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
--changeset rbac-base-PGSQL-ROLES:1 endDelimiter:--//
|
||||
--changeset rbac-base-PGSQL-ROLES:1 context:dev,tc endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
create role admin;
|
||||
grant all privileges on all tables in schema public to admin;
|
||||
|
||||
create role restricted;
|
||||
grant all privileges on all tables in schema public to restricted;
|
||||
do $$
|
||||
begin
|
||||
if '${HSADMINNG_POSTGRES_ADMIN_USERNAME}'='admin' then
|
||||
create role admin;
|
||||
grant all privileges on all tables in schema public to admin;
|
||||
end if;
|
||||
|
||||
if '${HSADMINNG_POSTGRES_RESTRICTED_USERNAME}'='restricted' then
|
||||
create role restricted;
|
||||
end if;
|
||||
-- grant all privileges on all tables in schema public to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
end $$
|
||||
--//
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
create or replace function assumedRoleUuid()
|
||||
returns uuid
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentSubjectsUuids uuid[];
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
create or replace function determineCurrentUserUuid(currentUser varchar)
|
||||
returns uuid
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentUserUuid uuid;
|
||||
@ -25,11 +25,11 @@ end; $$;
|
||||
|
||||
create or replace function determineCurrentSubjectsUuids(currentUserUuid uuid, assumedRoles varchar)
|
||||
returns uuid[]
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
roleName varchar(63);
|
||||
roleNameParts varchar(63);
|
||||
roleName text;
|
||||
roleNameParts text;
|
||||
objectTableToAssume varchar(63);
|
||||
objectNameToAssume varchar(63);
|
||||
objectUuidToAssume uuid;
|
||||
@ -116,7 +116,7 @@ end; $$;
|
||||
|
||||
create or replace function currentUserUuid()
|
||||
returns uuid
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentUserUuid text;
|
||||
@ -150,7 +150,7 @@ end; $$;
|
||||
*/
|
||||
create or replace function currentSubjectsUuids()
|
||||
returns uuid[]
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentSubjectsUuids text;
|
||||
|
@ -41,7 +41,7 @@ select *
|
||||
) as unordered
|
||||
-- @formatter:on
|
||||
order by objectTable || '#' || objectIdName || '.' || roleType;
|
||||
grant all privileges on rbacrole_rv to restricted;
|
||||
grant all privileges on rbacrole_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
--//
|
||||
|
||||
|
||||
@ -126,7 +126,7 @@ select o.objectTable || '#' || findIdNameByObjectUuid(o.objectTable, o.uuid) ||
|
||||
join RbacObject as o on o.uuid = r.objectUuid
|
||||
order by grantedRoleIdName;
|
||||
-- @formatter:on
|
||||
grant all privileges on rbacrole_rv to restricted;
|
||||
grant all privileges on rbacrole_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
--//
|
||||
|
||||
|
||||
@ -240,7 +240,7 @@ create or replace view RbacUser_rv as
|
||||
) as unordered
|
||||
-- @formatter:on
|
||||
order by unordered.name;
|
||||
grant all privileges on RbacUser_rv to restricted;
|
||||
grant all privileges on RbacUser_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
--//
|
||||
|
||||
-- ============================================================================
|
||||
@ -326,7 +326,7 @@ select r.uuid as roleuuid, p.uuid as permissionUuid,
|
||||
join rbacgrants g on g.ascendantuuid = r.uuid
|
||||
join rbacpermission p on p.uuid = g.descendantuuid
|
||||
join rbacobject o on o.uuid = p.objectuuid;
|
||||
grant all privileges on RbacOwnGrantedPermissions_rv to restricted;
|
||||
grant all privileges on RbacOwnGrantedPermissions_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
-- @formatter:om
|
||||
|
||||
-- ============================================================================
|
||||
|
@ -104,7 +104,7 @@ begin
|
||||
create or replace view %1$s_iv as
|
||||
select target.uuid, cleanIdentifier(%2$s) as idName
|
||||
from %1$s as target;
|
||||
grant all privileges on %1$s_iv to restricted;
|
||||
grant all privileges on %1$s_iv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
$sql$, targetTable, idNameExpression);
|
||||
execute sql;
|
||||
|
||||
@ -157,7 +157,7 @@ begin
|
||||
from %1$s as target
|
||||
where target.uuid in (select * from accessibleObjects)
|
||||
order by %2$s;
|
||||
grant all privileges on %1$s_rv to restricted;
|
||||
grant all privileges on %1$s_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
$sql$, targetTable, orderBy);
|
||||
execute sql;
|
||||
|
||||
|
@ -18,7 +18,7 @@ create table Global
|
||||
);
|
||||
create unique index Global_Singleton on Global ((0));
|
||||
|
||||
grant select on global to restricted;
|
||||
grant select on global to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
--//
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ drop view if exists global_iv;
|
||||
create or replace view global_iv as
|
||||
select target.uuid, target.name as idName
|
||||
from global as target;
|
||||
grant all privileges on global_iv to restricted;
|
||||
grant all privileges on global_iv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
|
||||
/*
|
||||
Returns the objectUuid for a given identifying name (in this case the idName).
|
||||
@ -99,7 +99,7 @@ commit;
|
||||
create or replace function globalAdmin()
|
||||
returns RbacRoleDescriptor
|
||||
returns null on null input
|
||||
stable leakproof
|
||||
stable -- leakproof
|
||||
language sql as $$
|
||||
select 'global', (select uuid from RbacObject where objectTable = 'global'), 'admin'::RbacRoleType;
|
||||
$$;
|
||||
|
@ -93,7 +93,7 @@ call generateRbacIdentityView('test_package', 'target.name');
|
||||
-- from test_package as target
|
||||
-- where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'test_package', currentSubjectsUuids()))
|
||||
-- order by target.name;
|
||||
-- grant all privileges on test_package_rv to restricted;
|
||||
-- grant all privileges on test_package_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
|
||||
call generateRbacRestrictedView('test_package', 'target.name',
|
||||
$updates$
|
||||
|
@ -110,5 +110,5 @@ create or replace view test_domain_rv as
|
||||
select target.*
|
||||
from test_domain as target
|
||||
where target.uuid in (select queryAccessibleObjectUuidsOfSubjectIds('view', 'domain', currentSubjectsUuids()));
|
||||
grant all privileges on test_domain_rv to restricted;
|
||||
grant all privileges on test_domain_rv to ${HSADMINNG_POSTGRES_RESTRICTED_USERNAME};
|
||||
--//
|
||||
|
@ -7,7 +7,7 @@
|
||||
create table if not exists hs_office_contact
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
label varchar(96) not null,
|
||||
label varchar(128) not null,
|
||||
postalAddress text,
|
||||
emailAddresses text, -- TODO.feat: change to json
|
||||
phoneNumbers text -- TODO.feat: change to json
|
||||
|
@ -26,9 +26,6 @@ create or replace function createRbacRolesForHsOfficeContact()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
strict as $$
|
||||
declare
|
||||
ownerRole uuid;
|
||||
adminRole uuid;
|
||||
begin
|
||||
if TG_OP <> 'INSERT' then
|
||||
raise exception 'invalid usage of TRIGGER AFTER INSERT';
|
||||
@ -107,7 +104,7 @@ do language plpgsql $$
|
||||
declare
|
||||
addCustomerPermissions uuid[];
|
||||
globalObjectUuid uuid;
|
||||
globalAdminRoleUuid uuid ;
|
||||
globalAdminRoleUuid uuid;
|
||||
begin
|
||||
call defineContext('granting global new-contact permission to global admin role', null, null, null);
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
--changeset hs-office-person-MAIN-TABLE:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficePersonType AS ENUM ('NATURAL', 'LEGAL', 'SOLE_REPRESENTATION', 'JOINT_REPRESENTATION');
|
||||
CREATE TYPE HsOfficePersonType AS ENUM ('UNKNOWN', 'NATURAL', 'LEGAL', 'SOLE_REPRESENTATION', 'JOINT_REPRESENTATION');
|
||||
|
||||
CREATE CAST (character varying as HsOfficePersonType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
|
@ -37,6 +37,7 @@ begin
|
||||
grantedByRole => globalAdmin()
|
||||
);
|
||||
|
||||
-- TODO: who is admin? the person itself? is it allowed for the person itself or a representative to edit the data?
|
||||
perform createRoleWithGrants(
|
||||
hsOfficePersonAdmin(NEW),
|
||||
permissions => array['edit'],
|
||||
|
@ -10,6 +10,7 @@ create table hs_office_partner_details
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
registrationOffice varchar(96),
|
||||
registrationNumber varchar(96),
|
||||
birthPlace varchar(96),
|
||||
birthName varchar(96),
|
||||
birthday date,
|
||||
dateOfDeath date
|
||||
@ -31,6 +32,7 @@ call create_journal('hs_office_partner_details');
|
||||
create table hs_office_partner
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
debitorNumberPrefix varchar(5),
|
||||
personUuid uuid not null references hs_office_person(uuid),
|
||||
contactUuid uuid not null references hs_office_contact(uuid),
|
||||
detailsUuid uuid not null references hs_office_partner_details(uuid) on delete cascade
|
||||
|
@ -27,7 +27,6 @@ create or replace function hsOfficePartnerRbacRolesTrigger()
|
||||
language plpgsql
|
||||
strict as $$
|
||||
declare
|
||||
hsOfficePartnerTenant RbacRoleDescriptor;
|
||||
oldPerson hs_office_person;
|
||||
newPerson hs_office_person;
|
||||
oldContact hs_office_contact;
|
||||
@ -166,6 +165,8 @@ execute procedure hsOfficePartnerRbacRolesTrigger();
|
||||
--changeset hs-office-partner-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacIdentityView('hs_office_partner', $idName$
|
||||
-- TODO: simplify by using just debitorNumberPrefix for the essential part
|
||||
debitorNumberPrefix || ':' ||
|
||||
(select idName from hs_office_person_iv p where p.uuid = target.personuuid)
|
||||
|| '-' ||
|
||||
(select idName from hs_office_contact_iv c where c.uuid = target.contactuuid)
|
||||
@ -179,6 +180,7 @@ call generateRbacIdentityView('hs_office_partner', $idName$
|
||||
call generateRbacRestrictedView('hs_office_partner',
|
||||
'(select idName from hs_office_person_iv p where p.uuid = target.personUuid)',
|
||||
$updates$
|
||||
debitorNumberPrefix = new.debitorNumberPrefix,
|
||||
personUuid = new.personUuid,
|
||||
contactUuid = new.contactUuid
|
||||
$updates$);
|
||||
|
@ -29,6 +29,7 @@ call generateRbacRestrictedView('hs_office_partner_details',
|
||||
$updates$
|
||||
registrationOffice = new.registrationOffice,
|
||||
registrationNumber = new.registrationNumber,
|
||||
birthPlace = new.birthPlace,
|
||||
birthName = new.birthName,
|
||||
birthday = new.birthday,
|
||||
dateOfDeath = new.dateOfDeath
|
||||
|
@ -8,7 +8,10 @@
|
||||
/*
|
||||
Creates a single partner test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficePartnerTestData( personTradeOrFamilyName varchar, contactLabel varchar )
|
||||
create or replace procedure createHsOfficePartnerTestData(
|
||||
debitorNumberPrefix numeric(5),
|
||||
personTradeOrFamilyName varchar,
|
||||
contactLabel varchar )
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentTask varchar;
|
||||
@ -51,8 +54,8 @@ begin
|
||||
end if;
|
||||
|
||||
insert
|
||||
into hs_office_partner (uuid, personuuid, contactuuid, detailsUuid)
|
||||
values (uuid_generate_v4(), relatedPerson.uuid, relatedContact.uuid, relatedDetailsUuid);
|
||||
into hs_office_partner (uuid, debitorNumberPrefix, personuuid, contactuuid, detailsUuid)
|
||||
values (uuid_generate_v4(), debitorNumberPrefix, relatedPerson.uuid, relatedContact.uuid, relatedDetailsUuid);
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
@ -64,11 +67,11 @@ end; $$;
|
||||
|
||||
do language plpgsql $$
|
||||
begin
|
||||
call createHsOfficePartnerTestData('First GmbH', 'first contact');
|
||||
call createHsOfficePartnerTestData('Second e.K.', 'second contact');
|
||||
call createHsOfficePartnerTestData('Third OHG', 'third contact');
|
||||
call createHsOfficePartnerTestData('Fourth e.G.', 'forth contact');
|
||||
call createHsOfficePartnerTestData('Smith', 'fifth contact');
|
||||
call createHsOfficePartnerTestData(10001, 'First GmbH', 'first contact');
|
||||
call createHsOfficePartnerTestData(10002, 'Second e.K.', 'second contact');
|
||||
call createHsOfficePartnerTestData(10003, 'Third OHG', 'third contact');
|
||||
call createHsOfficePartnerTestData(10004, 'Fourth e.G.', 'forth contact');
|
||||
call createHsOfficePartnerTestData(10010, 'Smith', 'fifth contact');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@ -4,7 +4,13 @@
|
||||
--changeset hs-office-relationship-MAIN-TABLE:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficeRelationshipType AS ENUM ('SOLE_AGENT', 'JOINT_AGENT', 'CO_OWNER', 'ACCOUNTING_CONTACT', 'TECHNICAL_CONTACT');
|
||||
CREATE TYPE HsOfficeRelationshipType AS ENUM (
|
||||
'UNKNOWN',
|
||||
'EX_PARTNER',
|
||||
'REPRESENTATIVE',
|
||||
'VIP_CONTACT',
|
||||
'ACCOUNTING',
|
||||
'OPERATIONS');
|
||||
|
||||
CREATE CAST (character varying as HsOfficeRelationshipType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
|
@ -58,7 +58,7 @@ begin
|
||||
select p.* from hs_office_person p where tradeName = intToVarChar(t, 4) into person;
|
||||
select c.* from hs_office_contact c where c.label = intToVarChar(t, 4) || '#' || t into contact;
|
||||
|
||||
call createHsOfficeRelationshipTestData(person.uuid, contact.uuid, 'SOLE_AGENT');
|
||||
call createHsOfficeRelationshipTestData(person.uuid, contact.uuid, 'REPRESENTATIVE');
|
||||
commit;
|
||||
end loop;
|
||||
end; $$;
|
||||
@ -71,11 +71,11 @@ end; $$;
|
||||
|
||||
do language plpgsql $$
|
||||
begin
|
||||
call createHsOfficeRelationshipTestData('First GmbH', 'Smith', 'SOLE_AGENT', 'first contact');
|
||||
call createHsOfficeRelationshipTestData('First GmbH', 'Smith', 'REPRESENTATIVE', 'first contact');
|
||||
|
||||
call createHsOfficeRelationshipTestData('Second e.K.', 'Smith', 'SOLE_AGENT', 'second contact');
|
||||
call createHsOfficeRelationshipTestData('Second e.K.', 'Smith', 'REPRESENTATIVE', 'second contact');
|
||||
|
||||
call createHsOfficeRelationshipTestData('Third OHG', 'Smith', 'SOLE_AGENT', 'third contact');
|
||||
call createHsOfficeRelationshipTestData('Third OHG', 'Smith', 'REPRESENTATIVE', 'third contact');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@ -6,7 +6,7 @@
|
||||
create table hs_office_bankaccount
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
holder varchar(27) not null,
|
||||
holder varchar(64) not null,
|
||||
iban varchar(34) not null,
|
||||
bic varchar(11) not null
|
||||
);
|
||||
|
@ -10,7 +10,7 @@
|
||||
CREATE TABLE hs_office_sepamandate_legacy_id
|
||||
(
|
||||
uuid uuid NOT NULL REFERENCES hs_office_sepamandate(uuid),
|
||||
sepa_mandat_id integer NOT NULL
|
||||
sepa_mandate_id integer NOT NULL
|
||||
);
|
||||
--//
|
||||
|
||||
@ -22,7 +22,7 @@ CREATE TABLE hs_office_sepamandate_legacy_id
|
||||
CREATE SEQUENCE IF NOT EXISTS hs_office_sepamandate_legacy_id_seq
|
||||
AS integer
|
||||
START 1000000000
|
||||
OWNED BY hs_office_sepamandate_legacy_id.sepa_mandat_id;
|
||||
OWNED BY hs_office_sepamandate_legacy_id.sepa_mandate_id;
|
||||
--//
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ CREATE SEQUENCE IF NOT EXISTS hs_office_sepamandate_legacy_id_seq
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
ALTER TABLE hs_office_sepamandate_legacy_id
|
||||
ALTER COLUMN sepa_mandat_id
|
||||
ALTER COLUMN sepa_mandate_id
|
||||
SET DEFAULT nextVal('hs_office_sepamandate_legacy_id_seq');
|
||||
|
||||
--/
|
||||
@ -42,7 +42,7 @@ ALTER TABLE hs_office_sepamandate_legacy_id
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CALL defineContext('schema-migration');
|
||||
INSERT INTO hs_office_sepamandate_legacy_id(uuid, sepa_mandat_id)
|
||||
INSERT INTO hs_office_sepamandate_legacy_id(uuid, sepa_mandate_id)
|
||||
SELECT uuid, nextVal('hs_office_sepamandate_legacy_id_seq') FROM hs_office_sepamandate;
|
||||
--/
|
||||
|
||||
|
@ -8,12 +8,18 @@ create table hs_office_debitor
|
||||
(
|
||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
||||
partnerUuid uuid not null references hs_office_partner(uuid),
|
||||
debitorNumber numeric(5) not null,
|
||||
billable boolean not null default true,
|
||||
debitorNumberSuffix numeric(2) not null,
|
||||
billingContactUuid uuid not null references hs_office_contact(uuid),
|
||||
vatId varchar(24), -- TODO.spec: here or in person?
|
||||
vatCountryCode varchar(2),
|
||||
vatBusiness boolean not null, -- TODO.spec: more of such?
|
||||
refundBankAccountUuid uuid references hs_office_bankaccount(uuid)
|
||||
vatBusiness boolean not null,
|
||||
vatReverseCharge boolean not null,
|
||||
refundBankAccountUuid uuid references hs_office_bankaccount(uuid),
|
||||
defaultPrefix char(3) not null unique
|
||||
constraint check_default_prefix check (
|
||||
defaultPrefix::text ~ '^([a-z]{3}|al0|bh1|c4s|f3k|k8i|l3d|mh1|o13|p2m|s80|t4w)$'
|
||||
)
|
||||
-- TODO.impl: SEPA-mandate
|
||||
);
|
||||
--//
|
||||
|
@ -172,8 +172,10 @@ execute procedure hsOfficeDebitorRbacRolesTrigger();
|
||||
--changeset hs-office-debitor-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacIdentityView('hs_office_debitor', $idName$
|
||||
'#' || debitorNumber || ':' ||
|
||||
(select idName from hs_office_partner_iv p where p.uuid = target.partnerUuid)
|
||||
'#' ||
|
||||
(select debitornumberprefix from hs_office_partner p where p.uuid = target.partnerUuid) ||
|
||||
to_char(debitorNumberSuffix, 'fm00') ||
|
||||
':' || (select split_part(idName, ':', 2) from hs_office_partner_iv pi where pi.uuid = target.partnerUuid)
|
||||
$idName$);
|
||||
--//
|
||||
|
||||
@ -181,14 +183,18 @@ call generateRbacIdentityView('hs_office_debitor', $idName$
|
||||
-- ============================================================================
|
||||
--changeset hs-office-debitor-rbac-RESTRICTED-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacRestrictedView('hs_office_debitor', 'target.debitorNumber',
|
||||
call generateRbacRestrictedView('hs_office_debitor', 'target.debitorNumberSuffix',
|
||||
$updates$
|
||||
partnerUuid = new.partnerUuid,
|
||||
partnerUuid = new.partnerUuid, -- TODO: remove? should never do anything
|
||||
billable = new.billable,
|
||||
billingContactUuid = new.billingContactUuid,
|
||||
debitorNumberSuffix = new.debitorNumberSuffix, -- TODO: Should it be allowed to updated this value?
|
||||
refundBankAccountUuid = new.refundBankAccountUuid,
|
||||
vatId = new.vatId,
|
||||
vatCountryCode = new.vatCountryCode,
|
||||
vatBusiness = new.vatBusiness
|
||||
vatBusiness = new.vatBusiness,
|
||||
vatreversecharge = new.vatreversecharge,
|
||||
defaultPrefix = new.defaultPrefix -- TODO: Should it be allowed to updated this value?
|
||||
$updates$);
|
||||
--//
|
||||
|
||||
|
@ -8,7 +8,12 @@
|
||||
/*
|
||||
Creates a single debitor test record.
|
||||
*/
|
||||
create or replace procedure createHsOfficeDebitorTestData( partnerTradeName varchar, billingContactLabel varchar )
|
||||
create or replace procedure createHsOfficeDebitorTestData(
|
||||
debitorNumberSuffix numeric(5),
|
||||
partnerTradeName varchar,
|
||||
billingContactLabel varchar,
|
||||
defaultPrefix varchar
|
||||
)
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentTask varchar;
|
||||
@ -16,7 +21,6 @@ declare
|
||||
relatedPartner hs_office_partner;
|
||||
relatedContact hs_office_contact;
|
||||
relatedBankAccountUuid uuid;
|
||||
newDebitorNumber numeric(6);
|
||||
begin
|
||||
idName := cleanIdentifier( partnerTradeName|| '-' || billingContactLabel);
|
||||
currentTask := 'creating debitor test-data ' || idName;
|
||||
@ -28,14 +32,13 @@ begin
|
||||
where person.tradeName = partnerTradeName into relatedPartner;
|
||||
select c.* from hs_office_contact c where c.label = billingContactLabel into relatedContact;
|
||||
select b.uuid from hs_office_bankaccount b where b.holder = partnerTradeName into relatedBankAccountUuid;
|
||||
select coalesce(max(debitorNumber)+1, 10001) from hs_office_debitor into newDebitorNumber;
|
||||
|
||||
raise notice 'creating test debitor: % (#%)', idName, newDebitorNumber;
|
||||
raise notice 'creating test debitor: % (#%)', idName, debitorNumberSuffix;
|
||||
raise notice '- using partner (%): %', relatedPartner.uuid, relatedPartner;
|
||||
raise notice '- using billingContact (%): %', relatedContact.uuid, relatedContact;
|
||||
insert
|
||||
into hs_office_debitor (uuid, partneruuid, debitornumber, billingcontactuuid, vatbusiness, refundbankaccountuuid)
|
||||
values (uuid_generate_v4(), relatedPartner.uuid, newDebitorNumber, relatedContact.uuid, true, relatedBankAccountUuid);
|
||||
into hs_office_debitor (uuid, partneruuid, debitornumbersuffix, billable, billingcontactuuid, vatbusiness, vatreversecharge, refundbankaccountuuid, defaultprefix)
|
||||
values (uuid_generate_v4(), relatedPartner.uuid, debitorNumberSuffix, true, relatedContact.uuid, true, false, relatedBankAccountUuid, defaultPrefix);
|
||||
end; $$;
|
||||
--//
|
||||
|
||||
@ -46,9 +49,9 @@ end; $$;
|
||||
|
||||
do language plpgsql $$
|
||||
begin
|
||||
call createHsOfficeDebitorTestData('First GmbH', 'first contact');
|
||||
call createHsOfficeDebitorTestData('Second e.K.', 'second contact');
|
||||
call createHsOfficeDebitorTestData('Third OHG', 'third contact');
|
||||
call createHsOfficeDebitorTestData(11, 'First GmbH', 'first contact', 'fir');
|
||||
call createHsOfficeDebitorTestData(12, 'Second e.K.', 'second contact', 'sec');
|
||||
call createHsOfficeDebitorTestData(13, 'Third OHG', 'third contact', 'thi');
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@ -4,7 +4,7 @@
|
||||
--changeset hs-office-membership-MAIN-TABLE:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
CREATE TYPE HsOfficeReasonForTermination AS ENUM ('NONE', 'CANCELLATION', 'TRANSFER', 'DEATH', 'LIQUIDATION', 'EXPULSION');
|
||||
CREATE TYPE HsOfficeReasonForTermination AS ENUM ('NONE', 'CANCELLATION', 'TRANSFER', 'DEATH', 'LIQUIDATION', 'EXPULSION', 'UNKNOWN');
|
||||
|
||||
CREATE CAST (character varying as HsOfficeReasonForTermination) WITH INOUT AS IMPLICIT;
|
||||
|
||||
@ -15,7 +15,8 @@ create table if not exists hs_office_membership
|
||||
mainDebitorUuid uuid not null references hs_office_debitor(uuid),
|
||||
memberNumber numeric(5) not null unique,
|
||||
validity daterange not null,
|
||||
reasonForTermination HsOfficeReasonForTermination not null default 'NONE'
|
||||
reasonForTermination HsOfficeReasonForTermination not null default 'NONE',
|
||||
membershipFeeBillable boolean not null default true
|
||||
);
|
||||
--//
|
||||
|
||||
|
@ -27,7 +27,7 @@ create or replace function hsOfficeMembershipRbacRolesTrigger()
|
||||
language plpgsql
|
||||
strict as $$
|
||||
declare
|
||||
newHsOfficePartner hs_office_partner;
|
||||
newHsOfficePartner hs_office_partner;
|
||||
newHsOfficeDebitor hs_office_debitor;
|
||||
begin
|
||||
|
||||
@ -92,7 +92,8 @@ execute procedure hsOfficeMembershipRbacRolesTrigger();
|
||||
--changeset hs-office-membership-rbac-IDENTITY-VIEW:1 endDelimiter:--//
|
||||
-- ----------------------------------------------------------------------------
|
||||
call generateRbacIdentityView('hs_office_membership', idNameExpression => $idName$
|
||||
target.memberNumber || (select idName from hs_office_partner_iv p where p.uuid = target.partnerUuid)
|
||||
target.memberNumber ||
|
||||
':' || (select split_part(idName, ':', 2) from hs_office_partner_iv p where p.uuid = target.partnerUuid)
|
||||
$idName$);
|
||||
--//
|
||||
|
||||
@ -104,7 +105,8 @@ call generateRbacRestrictedView('hs_office_membership',
|
||||
orderby => 'target.memberNumber',
|
||||
columnUpdates => $updates$
|
||||
validity = new.validity,
|
||||
reasonForTermination = new.reasonForTermination
|
||||
reasonForTermination = new.reasonForTermination,
|
||||
membershipFeeBillable = new.membershipFeeBillable
|
||||
$updates$);
|
||||
--//
|
||||
|
||||
|
@ -11,11 +11,11 @@
|
||||
create or replace procedure createHsOfficeMembershipTestData( forPartnerTradeName varchar, forMainDebitorNumber numeric )
|
||||
language plpgsql as $$
|
||||
declare
|
||||
currentTask varchar;
|
||||
idName varchar;
|
||||
relatedPartner hs_office_partner;
|
||||
relatedDebitor hs_office_debitor;
|
||||
newMemberNumber numeric;
|
||||
currentTask varchar;
|
||||
idName varchar;
|
||||
relatedPartner hs_office_partner;
|
||||
relatedDebitor hs_office_debitor;
|
||||
newMemberNumber numeric;
|
||||
begin
|
||||
idName := cleanIdentifier( forPartnerTradeName || '#' || forMainDebitorNumber);
|
||||
currentTask := 'creating Membership test-data ' || idName;
|
||||
@ -25,7 +25,7 @@ begin
|
||||
select partner.* from hs_office_partner partner
|
||||
join hs_office_person person on person.uuid = partner.personUuid
|
||||
where person.tradeName = forPartnerTradeName into relatedPartner;
|
||||
select d.* from hs_office_debitor d where d.debitorNumber = forMainDebitorNumber into relatedDebitor;
|
||||
select d.* from hs_office_debitor d where d.debitorNumberSuffix = forMainDebitorNumber into relatedDebitor;
|
||||
select coalesce(max(memberNumber)+1, 10001) from hs_office_membership into newMemberNumber;
|
||||
|
||||
raise notice 'creating test Membership: %', idName;
|
||||
@ -44,9 +44,9 @@ end; $$;
|
||||
|
||||
do language plpgsql $$
|
||||
begin
|
||||
call createHsOfficeMembershipTestData('First GmbH', 10001);
|
||||
call createHsOfficeMembershipTestData('Second e.K.', 10002);
|
||||
call createHsOfficeMembershipTestData('Third OHG', 10003);
|
||||
call createHsOfficeMembershipTestData('First GmbH', 11);
|
||||
call createHsOfficeMembershipTestData('Second e.K.', 12);
|
||||
call createHsOfficeMembershipTestData('Third OHG', 13);
|
||||
end;
|
||||
$$;
|
||||
--//
|
||||
|
@ -10,7 +10,8 @@ CREATE TYPE HsOfficeCoopAssetsTransactionType AS ENUM ('ADJUSTMENT',
|
||||
'TRANSFER',
|
||||
'ADOPTION',
|
||||
'CLEARING',
|
||||
'LOSS');
|
||||
'LOSS',
|
||||
'LIMITATION');
|
||||
|
||||
CREATE CAST (character varying as HsOfficeCoopAssetsTransactionType) WITH INOUT AS IMPLICIT;
|
||||
|
||||
|
@ -11,6 +11,8 @@ databaseChangeLog:
|
||||
file: db/changelog/005-uuid-ossp-extension.sql
|
||||
- include:
|
||||
file: db/changelog/006-numeric-hash-functions.sql
|
||||
- include:
|
||||
file: db/changelog/009-check-environment.sql
|
||||
- include:
|
||||
file: db/changelog/010-context.sql
|
||||
- include:
|
||||
|
Reference in New Issue
Block a user