add constraint hs_office_coopassetstransaction_reverse_entry_missing
This commit is contained in:
parent
6365d344ab
commit
41a166ed64
@ -17,16 +17,22 @@ CREATE CAST (character varying as HsOfficeCoopAssetsTransactionType) WITH INOUT
|
|||||||
|
|
||||||
create table if not exists hs_office_coopassetstransaction
|
create table if not exists hs_office_coopassetstransaction
|
||||||
(
|
(
|
||||||
uuid uuid unique references RbacObject (uuid) initially deferred,
|
uuid uuid unique, -- references RbacObject (uuid) initially deferred,
|
||||||
version int not null default 0,
|
version int not null default 0,
|
||||||
membershipUuid uuid not null references hs_office_membership(uuid),
|
membershipUuid uuid not null references hs_office_membership(uuid),
|
||||||
transactionType HsOfficeCoopAssetsTransactionType not null,
|
transactionType HsOfficeCoopAssetsTransactionType not null,
|
||||||
valueDate date not null,
|
valueDate date not null,
|
||||||
assetValue money not null,
|
assetValue money not null,
|
||||||
reference varchar(48) not null,
|
reference varchar(48) not null,
|
||||||
reverseEntryUuid uuid references hs_office_coopassetstransaction (uuid) deferrable ,
|
reverseEntryUuid uuid REFERENCES hs_office_coopassetstransaction(uuid) DEFERRABLE INITIALLY DEFERRED,
|
||||||
comment varchar(512)
|
comment varchar(512)
|
||||||
);
|
);
|
||||||
|
--//
|
||||||
|
|
||||||
|
|
||||||
|
-- ============================================================================
|
||||||
|
--changeset hs-office-coopassets-BUSINESS-RULES:1 endDelimiter:--//
|
||||||
|
-- ----------------------------------------------------------------------------
|
||||||
|
|
||||||
alter table hs_office_coopassetstransaction
|
alter table hs_office_coopassetstransaction
|
||||||
add constraint hs_office_coopassetstransaction_reverse_entry_missing
|
add constraint hs_office_coopassetstransaction_reverse_entry_missing
|
||||||
@ -48,10 +54,9 @@ BEGIN
|
|||||||
RAISE EXCEPTION 'reverseEntryUuid must refer to a row that has a reference back to this row and belongs to the same membership';
|
RAISE EXCEPTION 'reverseEntryUuid must refer to a row that has a reference back to this row and belongs to the same membership';
|
||||||
END; $$;
|
END; $$;
|
||||||
|
|
||||||
-- FIXME: why does this not work?
|
CREATE TRIGGER hs_office_coopassetstransaction_reverse_entry_is_reciprocal_tg
|
||||||
-- CREATE TRIGGER hs_office_coopassetstransaction_reverse_entry_is_reciprocal_tg
|
AFTER INSERT OR UPDATE ON hs_office_coopassetstransaction
|
||||||
-- AFTER INSERT OR UPDATE ON hs_office_coopassetstransaction
|
FOR EACH ROW EXECUTE FUNCTION hs_office_coopassetstransaction_reverse_entry_is_reciprocal_tf();
|
||||||
-- FOR EACH ROW EXECUTE FUNCTION hs_office_coopassetstransaction_reverse_entry_is_reciprocal_tf();
|
|
||||||
--//
|
--//
|
||||||
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
@ -66,9 +71,9 @@ declare
|
|||||||
totalAssetValue money;
|
totalAssetValue money;
|
||||||
begin
|
begin
|
||||||
select sum(cat.assetValue)
|
select sum(cat.assetValue)
|
||||||
from hs_office_coopassetstransaction cat
|
from hs_office_coopassetstransaction cat
|
||||||
where cat.membershipUuid = forMembershipUuid
|
where cat.membershipUuid = forMembershipUuid
|
||||||
into currentAssetValue;
|
into currentAssetValue;
|
||||||
totalAssetValue := currentAssetValue + newAssetValue;
|
totalAssetValue := currentAssetValue + newAssetValue;
|
||||||
if totalAssetValue::numeric < 0 then
|
if totalAssetValue::numeric < 0 then
|
||||||
raise exception '[400] coop assets transaction would result in a negative balance of assets';
|
raise exception '[400] coop assets transaction would result in a negative balance of assets';
|
||||||
@ -79,9 +84,9 @@ end; $$;
|
|||||||
alter table hs_office_coopassetstransaction
|
alter table hs_office_coopassetstransaction
|
||||||
add constraint hs_office_coopassets_positive
|
add constraint hs_office_coopassets_positive
|
||||||
check ( checkAssetsByMembershipUuid(membershipUuid, assetValue) );
|
check ( checkAssetsByMembershipUuid(membershipUuid, assetValue) );
|
||||||
|
|
||||||
--//
|
--//
|
||||||
|
|
||||||
|
|
||||||
-- ============================================================================
|
-- ============================================================================
|
||||||
--changeset hs-office-coopassets-MAIN-TABLE-JOURNAL:1 endDelimiter:--//
|
--changeset hs-office-coopassets-MAIN-TABLE-JOURNAL:1 endDelimiter:--//
|
||||||
-- ----------------------------------------------------------------------------
|
-- ----------------------------------------------------------------------------
|
||||||
|
@ -39,8 +39,8 @@ begin
|
|||||||
values
|
values
|
||||||
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit', null),
|
(uuid_generate_v4(), membership.uuid, 'DEPOSIT', '2010-03-15', 320.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-1', 'initial deposit', null),
|
||||||
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal', null),
|
(uuid_generate_v4(), membership.uuid, 'DISBURSAL', '2021-09-01', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-2', 'partial disbursal', null),
|
||||||
(lossEntryUuid, membership.uuid, 'LOSS', '2022-10-20', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some loss', adjustmentEntryUuid),
|
(lossEntryUuid, membership.uuid, 'DEPOSIT', '2022-10-20', 128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some loss', adjustmentEntryUuid),
|
||||||
(adjustmentEntryUuid, membership.uuid, 'ADJUSTMENT', '2022-10-21', 128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some adjustment', lossEntryUuid);
|
(adjustmentEntryUuid, membership.uuid, 'ADJUSTMENT', '2022-10-21', -128.00, 'ref '||givenPartnerNumber || givenMemberNumberSuffix||'-3', 'some adjustment', lossEntryUuid);
|
||||||
end; $$;
|
end; $$;
|
||||||
--//
|
--//
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers
|
url-tc: jdbc:tc:postgresql:15.5-bookworm:///spring_boot_testcontainers
|
||||||
url-local: jdbc:postgresql://localhost:5432/postgres
|
url-local: jdbc:postgresql://localhost:5432/postgres
|
||||||
url: ${spring.datasource.url-local}
|
url: ${spring.datasource.url-tc}
|
||||||
username: postgres
|
username: postgres
|
||||||
password: password
|
password: password
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user