From 1e26dc9401e63fbd906c39bd57929d32f4a455bd Mon Sep 17 00:00:00 2001 From: fleetside Date: Wed, 12 Sep 2018 14:48:59 -0400 Subject: [PATCH] dump of simple thoughts --- db_deploy.sql | 122 ++++++++++++++++----------------- schema/documents/bpr.json | 76 ++++++++++---------- schema/tables/acct.sql | 16 ++--- schema/tables/bal.sql | 30 ++++---- schema/tables/bpr.sql | 20 +++--- schema/tables/gl.sql | 24 +++---- schema/triggers/log_insert.sql | 30 ++++---- 7 files changed, 159 insertions(+), 159 deletions(-) diff --git a/db_deploy.sql b/db_deploy.sql index 1e327f0..fee4ad3 100644 --- a/db_deploy.sql +++ b/db_deploy.sql @@ -1,62 +1,62 @@ -BEGIN TRANSACTION; ---\conninfo ---drop schema evt cascade ---------------------------build schema---------------------------------------------- - -CREATE SCHEMA evt; -COMMENT ON SCHEMA evt IS 'event log'; - ---------------------------event log table------------------------------------------- - -CREATE TABLE evt.bpr ( - id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY - ,bpr JSONB - ,bprh JSONB - ,stmp timestamptz -); -COMMENT ON COLUMN evt.bpr.bpr IS 'basic pecuniary record'; -COMMENT ON COLUMN evt.bpr.bprh IS 'basic pecuniary record history'; -COMMENT ON COLUMN evt.bpr.stmp IS 'insert time'; - ---------------------------account master--------------------------------------------- - ---the account master should be dynamically created -CREATE TABLE evt.acct ( - acct text PRIMARY KEY - ,prop jsonb -); -COMMENT ON COLUMN evt.acct.acct IS 'account'; -COMMENT ON COLUMN evt.acct.prop IS 'properties'; - ---------------------------relational ledger------------------------------------------ - -CREATE TABLE evt.gl ( - id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY - ,bpr_id INT REFERENCES evt.bpr (id) - ,acct text REFERENCES evt.acct (acct) - ,amount numeric (12,2) - ,bpr jsonb -); -COMMENT ON COLUMN evt.gl.bpr_id IS 'id of initial basic pecuniary record'; -COMMENT ON COLUMN evt.gl.acct IS 'account code'; -COMMENT ON COLUMN evt.gl.amount IS 'amount'; -COMMENT ON COLUMN evt.gl.bpr IS 'extract from initial basic pecuniary record'; - ---------------------------balances---------------------------------------------------- - -CREATE TABLE evt.bal ( - acct TEXT REFERENCES evt.acct(acct) - ,perd daterange - ,obal numeric(12,2) - ,debits numeric(12,2) - ,credits numeric(12,2) - ,cbal numeric(12,2) -); -COMMENT ON COLUMN evt.bal.acct IS 'account'; -COMMENT ON COLUMN evt.bal.perd IS 'period'; -COMMENT ON COLUMN evt.bal.obal IS 'opening balance'; -COMMENT ON COLUMN evt.bal.debits IS 'total debits'; -COMMENT ON COLUMN evt.bal.credits IS 'total credits'; -COMMENT ON COLUMN evt.bal.cbal IS 'closing balance'; - +BEGIN TRANSACTION; +--\conninfo +--drop schema evt cascade +--------------------------build schema---------------------------------------------- + +CREATE SCHEMA evt; +COMMENT ON SCHEMA evt IS 'event log'; + +--------------------------event log table------------------------------------------- + +CREATE TABLE evt.bpr ( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY + ,bpr JSONB + ,bprh JSONB + ,stmp timestamptz +); +COMMENT ON COLUMN evt.bpr.bpr IS 'basic pecuniary record'; +COMMENT ON COLUMN evt.bpr.bprh IS 'basic pecuniary record history'; +COMMENT ON COLUMN evt.bpr.stmp IS 'insert time'; + +--------------------------account master--------------------------------------------- + +--the account master should be dynamically created +CREATE TABLE evt.acct ( + acct text PRIMARY KEY + ,prop jsonb +); +COMMENT ON COLUMN evt.acct.acct IS 'account'; +COMMENT ON COLUMN evt.acct.prop IS 'properties'; + +--------------------------relational ledger------------------------------------------ + +CREATE TABLE evt.gl ( + id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY + ,bpr_id INT REFERENCES evt.bpr (id) + ,acct text REFERENCES evt.acct (acct) + ,amount numeric (12,2) + ,bpr jsonb +); +COMMENT ON COLUMN evt.gl.bpr_id IS 'id of initial basic pecuniary record'; +COMMENT ON COLUMN evt.gl.acct IS 'account code'; +COMMENT ON COLUMN evt.gl.amount IS 'amount'; +COMMENT ON COLUMN evt.gl.bpr IS 'extract from initial basic pecuniary record'; + +--------------------------balances---------------------------------------------------- + +CREATE TABLE evt.bal ( + acct TEXT REFERENCES evt.acct(acct) + ,perd daterange + ,obal numeric(12,2) + ,debits numeric(12,2) + ,credits numeric(12,2) + ,cbal numeric(12,2) +); +COMMENT ON COLUMN evt.bal.acct IS 'account'; +COMMENT ON COLUMN evt.bal.perd IS 'period'; +COMMENT ON COLUMN evt.bal.obal IS 'opening balance'; +COMMENT ON COLUMN evt.bal.debits IS 'total debits'; +COMMENT ON COLUMN evt.bal.credits IS 'total credits'; +COMMENT ON COLUMN evt.bal.cbal IS 'closing balance'; + COMMIT; \ No newline at end of file diff --git a/schema/documents/bpr.json b/schema/documents/bpr.json index 75f55e0..8c22025 100644 --- a/schema/documents/bpr.json +++ b/schema/documents/bpr.json @@ -1,39 +1,39 @@ -{ - "gl": [ - { - "jpath": [ - "{item,0}", - "{header}" - ], - "amount": 2.19, - "account": "h.food" - }, - { - "jpath": [ - "{item,0}", - "{header}" - ], - "amount": -2.19, - "account": "h.dcard" - } - ], - "item": [ - { - "item": "green olives", - "amount": 2.19, - "reason": "food", - "account": "h.food" - } - ], - "header": { - "entity": "home", - "module": "MHI", - "offset": "h.dcard", - "vendor": "Discount Drug Mart", - "currency": "USD", - "eff_date": "1/6/2018", - "location": "Stow, OH", - "instrument": "Discover Card", - "transaction": "purchase" - } +{ + "gl": [ + { + "jpath": [ + "{item,0}", + "{header}" + ], + "amount": 2.19, + "account": "h.food" + }, + { + "jpath": [ + "{item,0}", + "{header}" + ], + "amount": -2.19, + "account": "h.dcard" + } + ], + "item": [ + { + "item": "green olives", + "amount": 2.19, + "reason": "food", + "account": "h.food" + } + ], + "header": { + "entity": "home", + "module": "MHI", + "offset": "h.dcard", + "vendor": "Discount Drug Mart", + "currency": "USD", + "eff_date": "1/6/2018", + "location": "Stow, OH", + "instrument": "Discover Card", + "transaction": "purchase" + } } \ No newline at end of file diff --git a/schema/tables/acct.sql b/schema/tables/acct.sql index 4badfe0..c92800e 100644 --- a/schema/tables/acct.sql +++ b/schema/tables/acct.sql @@ -1,9 +1,9 @@ ---------------------------account master--------------------------------------------- - ---the account master should be dynamically created -CREATE TABLE evt.acct ( - acct text PRIMARY KEY - ,prop jsonb -); -COMMENT ON COLUMN evt.acct.acct IS 'account'; +--------------------------account master--------------------------------------------- + +--the account master should be dynamically created +CREATE TABLE evt.acct ( + acct text PRIMARY KEY + ,prop jsonb +); +COMMENT ON COLUMN evt.acct.acct IS 'account'; COMMENT ON COLUMN evt.acct.prop IS 'properties'; \ No newline at end of file diff --git a/schema/tables/bal.sql b/schema/tables/bal.sql index 2513b2b..797f804 100644 --- a/schema/tables/bal.sql +++ b/schema/tables/bal.sql @@ -1,16 +1,16 @@ ---------------------------balances---------------------------------------------------- - -CREATE TABLE evt.bal ( - acct TEXT REFERENCES evt.acct(acct) - ,perd daterange - ,obal numeric(12,2) - ,debits numeric(12,2) - ,credits numeric(12,2) - ,cbal numeric(12,2) -); -COMMENT ON COLUMN evt.bal.acct IS 'account'; -COMMENT ON COLUMN evt.bal.perd IS 'period'; -COMMENT ON COLUMN evt.bal.obal IS 'opening balance'; -COMMENT ON COLUMN evt.bal.debits IS 'total debits'; -COMMENT ON COLUMN evt.bal.credits IS 'total credits'; +--------------------------balances---------------------------------------------------- + +CREATE TABLE evt.bal ( + acct TEXT REFERENCES evt.acct(acct) + ,perd daterange + ,obal numeric(12,2) + ,debits numeric(12,2) + ,credits numeric(12,2) + ,cbal numeric(12,2) +); +COMMENT ON COLUMN evt.bal.acct IS 'account'; +COMMENT ON COLUMN evt.bal.perd IS 'period'; +COMMENT ON COLUMN evt.bal.obal IS 'opening balance'; +COMMENT ON COLUMN evt.bal.debits IS 'total debits'; +COMMENT ON COLUMN evt.bal.credits IS 'total credits'; COMMENT ON COLUMN evt.bal.cbal IS 'closing balance'; \ No newline at end of file diff --git a/schema/tables/bpr.sql b/schema/tables/bpr.sql index 64f56d4..b82aa46 100644 --- a/schema/tables/bpr.sql +++ b/schema/tables/bpr.sql @@ -1,11 +1,11 @@ ---------------------------event log table------------------------------------------- - -CREATE TABLE evt.bpr ( - id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY - ,bpr JSONB - ,bprh JSONB - ,stmp timestamptz -); -COMMENT ON COLUMN evt.bpr.bpr IS 'basic pecuniary record'; -COMMENT ON COLUMN evt.bpr.bprh IS 'basic pecuniary record history'; +--------------------------event log table------------------------------------------- + +CREATE TABLE evt.bpr ( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY + ,bpr JSONB + ,bprh JSONB + ,stmp timestamptz +); +COMMENT ON COLUMN evt.bpr.bpr IS 'basic pecuniary record'; +COMMENT ON COLUMN evt.bpr.bprh IS 'basic pecuniary record history'; COMMENT ON COLUMN evt.bpr.stmp IS 'insert time'; \ No newline at end of file diff --git a/schema/tables/gl.sql b/schema/tables/gl.sql index e2d9794..cae7ed3 100644 --- a/schema/tables/gl.sql +++ b/schema/tables/gl.sql @@ -1,13 +1,13 @@ ---------------------------relational ledger------------------------------------------ - -CREATE TABLE evt.gl ( - id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY - ,bpr_id INT REFERENCES evt.bpr (id) - ,acct text REFERENCES evt.acct (acct) - ,amount numeric (12,2) - ,bpr jsonb -); -COMMENT ON COLUMN evt.gl.bpr_id IS 'id of initial basic pecuniary record'; -COMMENT ON COLUMN evt.gl.acct IS 'account code'; -COMMENT ON COLUMN evt.gl.amount IS 'amount'; +--------------------------relational ledger------------------------------------------ + +CREATE TABLE evt.gl ( + id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY + ,bpr_id INT REFERENCES evt.bpr (id) + ,acct text REFERENCES evt.acct (acct) + ,amount numeric (12,2) + ,bpr jsonb +); +COMMENT ON COLUMN evt.gl.bpr_id IS 'id of initial basic pecuniary record'; +COMMENT ON COLUMN evt.gl.acct IS 'account code'; +COMMENT ON COLUMN evt.gl.amount IS 'amount'; COMMENT ON COLUMN evt.gl.bpr IS 'extract from initial basic pecuniary record'; \ No newline at end of file diff --git a/schema/triggers/log_insert.sql b/schema/triggers/log_insert.sql index 2513b2b..797f804 100644 --- a/schema/triggers/log_insert.sql +++ b/schema/triggers/log_insert.sql @@ -1,16 +1,16 @@ ---------------------------balances---------------------------------------------------- - -CREATE TABLE evt.bal ( - acct TEXT REFERENCES evt.acct(acct) - ,perd daterange - ,obal numeric(12,2) - ,debits numeric(12,2) - ,credits numeric(12,2) - ,cbal numeric(12,2) -); -COMMENT ON COLUMN evt.bal.acct IS 'account'; -COMMENT ON COLUMN evt.bal.perd IS 'period'; -COMMENT ON COLUMN evt.bal.obal IS 'opening balance'; -COMMENT ON COLUMN evt.bal.debits IS 'total debits'; -COMMENT ON COLUMN evt.bal.credits IS 'total credits'; +--------------------------balances---------------------------------------------------- + +CREATE TABLE evt.bal ( + acct TEXT REFERENCES evt.acct(acct) + ,perd daterange + ,obal numeric(12,2) + ,debits numeric(12,2) + ,credits numeric(12,2) + ,cbal numeric(12,2) +); +COMMENT ON COLUMN evt.bal.acct IS 'account'; +COMMENT ON COLUMN evt.bal.perd IS 'period'; +COMMENT ON COLUMN evt.bal.obal IS 'opening balance'; +COMMENT ON COLUMN evt.bal.debits IS 'total debits'; +COMMENT ON COLUMN evt.bal.credits IS 'total credits'; COMMENT ON COLUMN evt.bal.cbal IS 'closing balance'; \ No newline at end of file