1
0

bugfix/only-one-partner-per-person (#143)

Co-authored-by: Michael Hoennig <michael@hoennig.de>
Reviewed-on: https://dev.hostsharing.net/hostsharing/hs.hsadmin.ng/pulls/143
Reviewed-by: Marc Sandlus <marc.sandlus@hostsharing.net>
This commit is contained in:
Michael Hoennig
2025-01-07 09:30:25 +01:00
parent b3f1171561
commit 6b09ad0003
14 changed files with 100 additions and 54 deletions

View File

@@ -251,7 +251,7 @@ begin
execute sql into uuid;
exception
when others then
raise exception 'function %_uuid_by_id_name(''%'') failed: %, SQLSTATE: %. If it could not be found, add identity view support to %\nSQL:%',
raise exception 'function %_uuid_by_id_name(''%'') failed: %, SQLSTATE: %. If the function itself could not be found, add identity view support to %\nSQL:%',
objectTable, objectIdName, SQLERRM, SQLSTATE, objectTable, sql;
end;
if uuid is null then
@@ -275,7 +275,7 @@ begin
execute sql into idName;
exception
when others then
raise exception 'function %_id_name_by_uuid(''%'') failed: %, SQLSTATE: %. If it could not be found, add identity view support to %',
raise exception 'function %_id_name_by_uuid(''%'') failed: %, SQLSTATE: %. If the function itself could not be found, add identity view support to %',
objectTable, objectUuid, SQLERRM, SQLSTATE, objectTable;
end;
return idName;

View File

@@ -29,8 +29,24 @@ create table if not exists hs_office.relation
);
--//
-- TODO.impl: unique constraint, to prevent using the same person multiple times as a partner, or better:
-- ( anchorUuid, holderUuid, type)
-- ============================================================================
--changeset michael.hoennig:hs-office-relation-unique-constraints endDelimiter:--//
-- ----------------------------------------------------------------------------
CREATE UNIQUE INDEX unique_relation_with_mark
ON hs_office.relation (type, anchorUuid, holderUuid, contactUuid, mark)
WHERE mark IS NOT NULL;
CREATE UNIQUE INDEX unique_relation_without_mark
ON hs_office.relation (type, anchorUuid, holderUuid, contactUuid)
WHERE mark IS NULL;
CREATE UNIQUE INDEX unique_partner_relation
ON hs_office.relation (type, anchorUuid, holderUuid)
WHERE mark IS NULL AND type = 'PARTNER';
--//
-- ============================================================================

View File

@@ -100,8 +100,8 @@ do language plpgsql $$
call hs_office.relation_create_test_data('Third OHG', 'DEBITOR', 'Third OHG', 'third contact');
call hs_office.relation_create_test_data('Fourth eG', 'PARTNER', 'Hostsharing eG', 'fourth contact');
call hs_office.relation_create_test_data('Fouler', 'REPRESENTATIVE', 'Third OHG', 'third contact');
call hs_office.relation_create_test_data('Third OHG', 'DEBITOR', 'Third OHG', 'third contact');
call hs_office.relation_create_test_data('Fouler', 'REPRESENTATIVE', 'Fourth eG', 'fourth contact');
call hs_office.relation_create_test_data('Fourth eG', 'DEBITOR', 'Fourth eG', 'fourth contact');
call hs_office.relation_create_test_data('Smith', 'PARTNER', 'Hostsharing eG', 'sixth contact');
call hs_office.relation_create_test_data('Smith', 'DEBITOR', 'Smith', 'third contact');