From 9d56c494112d234983f71cc2b2c0a456c1f8f46d Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 19 Sep 2018 22:24:10 -0400 Subject: [PATCH 1/2] rename folder --- schema/suggested_data/periods.sql | 32 ++++++++++++++++++++++++ schema/suggested_date/periods.sql | 41 ------------------------------- 2 files changed, 32 insertions(+), 41 deletions(-) create mode 100644 schema/suggested_data/periods.sql delete mode 100644 schema/suggested_date/periods.sql diff --git a/schema/suggested_data/periods.sql b/schema/suggested_data/periods.sql new file mode 100644 index 0000000..b437ecd --- /dev/null +++ b/schema/suggested_data/periods.sql @@ -0,0 +1,32 @@ +WITH +--startign month +startm AS ( + SELECT 1 as m +) +,m AS ( + SELECT + g.s calendar_month + ,startm.m starting_month + ,g.s + CASE WHEN g.s < startm.m THEN startm.m +1 ELSE -startm.m +1 END fisc_month + FROM + generate_series(1,12,1) g(s) + CROSS JOIN startm +) +--select * from m +INSERT INTO + evt.fspr +SELECT + --TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1 + ( + --year + to_char(extract(year from gs.d),'FM0000') + --month + ||'.'||to_char(m.fisc_month,'FM00') + )::ltree t2 + ,tstzrange(gs.d,gs.d + '1 month'::interval) r +FROM + generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 month') gs(d) + INNER JOIN m ON + m.calendar_month = extract(month from gs.d) +ORDER BY + gs.d ASC diff --git a/schema/suggested_date/periods.sql b/schema/suggested_date/periods.sql deleted file mode 100644 index 8a66161..0000000 --- a/schema/suggested_date/periods.sql +++ /dev/null @@ -1,41 +0,0 @@ -WITH ---startign month -m as ( - SELECT - * - FROM - ( - VALUES - (1,1,1) - ,(2,2,1) - ,(3,3,1) - ,(4,4,2) - ,(5,5,2) - ,(6,6,2) - ,(7,7,3) - ,(8,8,3) - ,(9,9,3) - ,(10,10,4) - ,(11,11,4) - ,(12,12,4) - ) X (cm,fm,fq) -) -INSERT INTO - evt.fspr -SELECT - --TO_CHAR(gs.d,'YYYY.MM.DD')::ltree t1 - ( - --year - to_char(extract(year from gs.d),'FM0000') - --quarter - ||'.'||to_char(m.fq,'FM00') - --month - ||'.'||to_char(m.fm,'FM00') - --day - ||'.'||to_char(extract(day from gs.d),'FM00') - )::ltree t2 - ,tstzrange(gs.d,gs.d + '1 month'::interval) r -FROM - generate_series('2018-01-01 00:00'::timestamptz,'2099-12-01 00:00'::timestamptz,'1 month') gs(d) - INNER JOIN m ON - m.cm = extract(month from gs.d) \ No newline at end of file From 0d4b8a91141a361fbc42111a10148211126c32cf Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 19 Sep 2018 22:24:27 -0400 Subject: [PATCH 2/2] periods --- db_deploy.sql | 15 ++++++++++++++- schema/tables/fspr.sql | 9 +++++++++ schema/tables/perd.sql | 5 ----- 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 schema/tables/fspr.sql delete mode 100644 schema/tables/perd.sql diff --git a/db_deploy.sql b/db_deploy.sql index 3970cb3..382c993 100644 --- a/db_deploy.sql +++ b/db_deploy.sql @@ -1,8 +1,11 @@ BEGIN TRANSACTION; --\conninfo -drop schema evt cascade; + --------------------------build schema---------------------------------------------- +DROP EXTENSTION IF EXISTS ltree; +CREATE EXTENSTION ltree; +DROP SCHEMA IF EXISTS evt cascade; CREATE SCHEMA evt; COMMENT ON SCHEMA evt IS 'event log'; @@ -28,6 +31,16 @@ CREATE TABLE evt.acct ( COMMENT ON COLUMN evt.acct.acct IS 'account'; COMMENT ON COLUMN evt.acct.prop IS 'properties'; +------------------------fiscal periods------------------------ +CREATE TABLE evt.fspr ( + id ltree + ,dur tstzrange +) + +CREATE INDEX fspr_id ON evt.fspr USING GIST (id); +COMMENT ON COLUMN evt.fspr.id IS 'fiscal period id'; +COMMENT ON COLUMN evt.fspr.dur IS 'fiscal period dutation in timestamp range'; + --------------------------relational ledger------------------------------------------ CREATE TABLE evt.gl ( diff --git a/schema/tables/fspr.sql b/schema/tables/fspr.sql new file mode 100644 index 0000000..037dc95 --- /dev/null +++ b/schema/tables/fspr.sql @@ -0,0 +1,9 @@ +------------------------fiscal periods------------------------ +CREATE TABLE evt.fspr ( + id ltree + ,dur tstzrange +) + +CREATE INDEX fspr_id ON evt.fspr USING GIST (id); +COMMENT ON COLUMN evt.fspr.id IS 'fiscal period id'; +COMMENT ON COLUMN evt.fspr.dur IS 'fiscal period dutation in timestamp range'; \ No newline at end of file diff --git a/schema/tables/perd.sql b/schema/tables/perd.sql deleted file mode 100644 index b967650..0000000 --- a/schema/tables/perd.sql +++ /dev/null @@ -1,5 +0,0 @@ -------------------------fiscal periods------------------------ -CREATE TABLE evt.fspr ( - id ltree - ,dur tstzrange -) \ No newline at end of file