diff --git a/db_deploy.sql b/db_deploy.sql index 3b743b4..1361ee1 100644 --- a/db_deploy.sql +++ b/db_deploy.sql @@ -31,6 +31,9 @@ COMMENT ON TABLE evt.acct IS 'account master list'; COMMENT ON COLUMN evt.acct.acct IS 'account'; COMMENT ON COLUMN evt.acct.prop IS 'properties'; +--this should effectively only allow one instance of an account where retained_earnings = set per top level account (trial balance) +CREATE UNIQUE INDEX acct_re ON evt.acct (subpath(acct,0,1)) WHERE prop ->> 'retained_earnings' = 'set'; + ------------------------fiscal periods------------------------ CREATE TABLE evt.fspr ( id ltree PRIMARY KEY diff --git a/schema/tables/acct.sql b/schema/tables/acct.sql index 77ce91a..9df6657 100644 --- a/schema/tables/acct.sql +++ b/schema/tables/acct.sql @@ -8,3 +8,6 @@ CREATE TABLE evt.acct ( COMMENT ON TABLE evt.acct IS 'account master list'; COMMENT ON COLUMN evt.acct.acct IS 'account'; COMMENT ON COLUMN evt.acct.prop IS 'properties'; + +--this should effectively only allow one instance of an account where retained_earnings = set per top level account (trial balance) +CREATE UNIQUE INDEX acct_re ON evt.acct (subpath(acct,0,1)) WHERE prop ->> 'retained_earnings' = 'set';