From 8bda52f770dabf6494bd71a8356638010bf71721 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 12 Apr 2022 22:58:31 -0400 Subject: [PATCH] get rid of clone files; move mapping to readme; rename setup to sequence the operations --- readme.md | 34 ++++++ setup_sql/{schema.sql => 01_schema.sql} | 0 .../{target_info.sql => 02_target_info.sql} | 0 ..._tables.sql => 03_build_master_tables.sql} | 0 setup_sql/clone.sql | 111 ------------------ setup_sql/clone_meta.sql | 31 ----- setup_sql/gen_clone.sql | 49 -------- setup_sql/generate_clone_sql.sh | 4 - setup_sql/mapping.md | 34 ------ 9 files changed, 34 insertions(+), 229 deletions(-) rename setup_sql/{schema.sql => 01_schema.sql} (100%) rename setup_sql/{target_info.sql => 02_target_info.sql} (100%) rename setup_sql/{build_master_tables.sql => 03_build_master_tables.sql} (100%) delete mode 100644 setup_sql/clone.sql delete mode 100644 setup_sql/clone_meta.sql delete mode 100644 setup_sql/gen_clone.sql delete mode 100755 setup_sql/generate_clone_sql.sh delete mode 100644 setup_sql/mapping.md diff --git a/readme.md b/readme.md index a9236bf..ac5c415 100644 --- a/readme.md +++ b/readme.md @@ -10,6 +10,40 @@ setup * `PGD -f setup_sql/build_maste_tables.sql` to create master data tables from forecast data * `./routes/baseline/generate_route_sql.sh` to create the baseline sql used by the /baseline route +| schema | tname | cname | opos | func | fkey | fcol | dtype | appcol | pretty | +| ------- | ------- | -------------- | ---- | ------------ | ------------ | -------------- | ------- | ------------ | ------ | +| fc | live | fb_cst_loc | 91 | cost | | fb_cst_loc | numeric | | | +| fc | live | ship_cust | 36 | scust | scust | ship_cust | text | | | +| fc | live | rdate | 98 | rdate | rdate | drange | date | | | +| fc | live | geo | 42 | scust | | geo | text | customer | | +| fc | live | part | 54 | item | item | part | text | item | | +| fc | live | odate | 96 | odate | odate | drange | date | order_date | | +| fc | live | sdate | 100 | sdate | sdate | sdate | date | ship_date | | +| fc | live | oseas | 97 | odate | | ssyr | integer | | | +| fc | live | calc_status | 94 | order_status | order_status | calc_status | text | order_status | | +| fc | live | rseas | 99 | rdate | | ssyr | integer | | | +| fc | live | sseas | 101 | sdate | | ssyr | integer | | | +| | | | | | | | | version | | +| | | | | | | | | iter | | +| | | | | | | | | logid | | + +* func: table name of associated data +* fkey: primary key of assoicated dat +* fcol: associated field from the master data table if it is different (oseas would refer to ssyr in fc.perd) +* pretty: display column name (user friendly) +* appcol: parameters that will have to be supplied but the application + * order_date + * ship_date + * customer + * item + * order_stats + * units + * cost + * value + * version (added if missing) + * iter (added if missing) + * logid (added if missing) + routes ---------------------------------------------------------------------------------------------------------------------------------------------------- * all routes would be tied to an underlying sql that builds the incremental rows diff --git a/setup_sql/schema.sql b/setup_sql/01_schema.sql similarity index 100% rename from setup_sql/schema.sql rename to setup_sql/01_schema.sql diff --git a/setup_sql/target_info.sql b/setup_sql/02_target_info.sql similarity index 100% rename from setup_sql/target_info.sql rename to setup_sql/02_target_info.sql diff --git a/setup_sql/build_master_tables.sql b/setup_sql/03_build_master_tables.sql similarity index 100% rename from setup_sql/build_master_tables.sql rename to setup_sql/03_build_master_tables.sql diff --git a/setup_sql/clone.sql b/setup_sql/clone.sql deleted file mode 100644 index 82fbf5f..0000000 --- a/setup_sql/clone.sql +++ /dev/null @@ -1,111 +0,0 @@ -CREATE TABLE IF NOT EXISTS fc.live AS ( -SELECT -o."ddord#" - ,o."dditm#" - ,o."fgbol#" - ,o."fgent#" - ,o."diinv#" - ,o."dilin#" - ,o.quoten - ,o.quotel - ,o.dcodat - ,o.ddqdat - ,o.dcmdat - ,o.fesdat - ,o.dhidat - ,o.fesind - ,o.dhpost - ,o.fspr - ,o.ddqtoi - ,o.ddqtsi - ,o.fgqshp - ,o.diqtsh - ,o.diext - ,o.ditdis - ,o.discj - ,o.dhincr - ,o.plnt - ,o.promo - ,o.return_reas - ,o.terms - ,o.custpo - ,o.remit_to - ,o.bill_class - ,o.bill_cust - ,o.bill_rep - ,o.bill_terr - ,o.ship_class - ,o.ship_cust - ,o.ship_rep - ,o.ship_terr - ,o.dsm - ,o.account - ,o.shipgrp - ,o.geo - ,o.chan - ,o.chansub - ,o.orig_ctry - ,o.orig_prov - ,o.orig_post - ,o.bill_ctry - ,o.bill_prov - ,o.bill_post - ,o.dest_ctry - ,o.dest_prov - ,o.dest_post - ,o.part - ,o.styc - ,o.colc - ,o.colgrp - ,o.coltier - ,o.colstat - ,o.sizc - ,o.pckg - ,o.kit - ,o.brnd - ,o.majg - ,o.ming - ,o.majs - ,o.mins - ,o.gldco - ,o.gldc - ,o.glec - ,o.harm - ,o.clss - ,o.brand - ,o.assc - ,o.ddunit - ,o.unti - ,o.lbs - ,o.plt - ,o.plcd - ,o.fs_line - ,o.r_currency - ,o.r_rate - ,o.c_currency - ,o.c_rate - ,o.fb_qty - ,o.fb_val_loc - ,o.fb_val_loc_dis - ,o.fb_val_loc_qt - ,o.fb_val_loc_pl - ,o.fb_val_loc_tar - ,o.fb_cst_loc - ,o.fb_cst_loc_cur - ,o.fb_cst_loc_fut - ,o.calc_status - ,o.flag - ,o.odate - ,o.oseas - ,o.rdate - ,o.rseas - ,o.sdate - ,o.sseas - ,o.version - ,o.iter - ,null::text AS _comment - ,null::integer AS _logid - ,null::text AS _tag -FROM - rlarp.osm_dev o -) WITH DATA; diff --git a/setup_sql/clone_meta.sql b/setup_sql/clone_meta.sql deleted file mode 100644 index 2b42e79..0000000 --- a/setup_sql/clone_meta.sql +++ /dev/null @@ -1,31 +0,0 @@ -BEGIN; -INSERT INTO - fc.target_meta -SELECT - --hard-coded name of new clone table - 'fc.live' tname - ,cname - ,opos - ,func - ,fkey - ,pretty - ,dtype - ,mastcol - ,appcol - ,dateref -FROM - fc.target_meta -WHERE - --hard-coded original sales data with mapped fields - tname = 'rlarp.osm_dev' -ON CONFLICT ON CONSTRAINT target_meta_pk DO UPDATE SET - func = EXCLUDED.func - ,pretty = EXCLUDED.pretty - ,mastcol = EXCLUDED.mastcol - ,appcol = EXCLUDED.appcol - ,dateref = EXCLUDED.dateref - ,fkey = EXCLUDED.fkey; ---SELECT * FROM fc.target_meta WHERE tname = 'fc.live'; ---ROLLBACK; -COMMIT; -END; diff --git a/setup_sql/gen_clone.sql b/setup_sql/gen_clone.sql deleted file mode 100644 index 346d5d0..0000000 --- a/setup_sql/gen_clone.sql +++ /dev/null @@ -1,49 +0,0 @@ -DO -$func$ -DECLARE - _clist text; - _targ text; - _sql text; - -BEGIN ------------------------------this target would be replaced with a parameter-------------- -SELECT - 'rlarp.osm_dev o' -INTO - _targ; - --------------------------------build a column list----------------------------------------- ------------a list of required columns is in fc.appcols, if they are not present------------ ------------they will have to build included------------------------------------------------ -SELECT - string_agg( - --if the colum name is empty that means we are dealig with a required appcol - --that isn't present: use the appcol.col for the name preceded by underscore - CASE WHEN m.cname IS NULL - THEN COALESCE(a.dflt,'null::'||a.dtype)||' AS _'||a.col - ELSE 'o.'||format('%I',COALESCE(cname,'')) - END - ,E'\n ,' ORDER BY opos ASC) -INTO - _clist -FROM - fc.target_meta m - FULL OUTER JOIN fc.appcols a ON - m.appcol = a.col - AND m.dtype = a.dtype -WHERE - tname = _targ; - -_sql:= $$CREATE TABLE IF NOT EXISTS fc.live AS ( -SELECT -$$||_clist||$$ -FROM - $$||_targ||$$ -) WITH DATA;$$; - ---RAISE NOTICE '%', _sql; - -INSERT INTO fc.sql SELECT 'live', _sql ON CONFLICT ON CONSTRAINT sql_pkey DO UPDATE SET t = EXCLUDED.t; - -END; -$func$ diff --git a/setup_sql/generate_clone_sql.sh b/setup_sql/generate_clone_sql.sh deleted file mode 100755 index 89af4ad..0000000 --- a/setup_sql/generate_clone_sql.sh +++ /dev/null @@ -1,4 +0,0 @@ -# execure the sql for scale which builds the sql and inserts into a table -$PGD -f gen_clone.sql -# pull the sql out of the table and write it to route directory -$PGD -c "SELECT t FROM fc.sql WHERE cmd = 'clone'" -t -A -o clone.sql diff --git a/setup_sql/mapping.md b/setup_sql/mapping.md deleted file mode 100644 index f2bc924..0000000 --- a/setup_sql/mapping.md +++ /dev/null @@ -1,34 +0,0 @@ -| schema | tname | cname | opos | func | fkey | fcol | dtype | appcol | pretty | -| ------- | ------- | -------------- | ---- | ------------ | ------------ | -------------- | ------- | ------------ | ------ | -| fc | live | fb_cst_loc | 91 | cost | | fb_cst_loc | numeric | | | -| fc | live | ship_cust | 36 | scust | scust | ship_cust | text | | | -| fc | live | rdate | 98 | rdate | rdate | drange | date | | | -| fc | live | geo | 42 | scust | | geo | text | customer | | -| fc | live | part | 54 | item | item | part | text | item | | -| fc | live | odate | 96 | odate | odate | drange | date | order_date | | -| fc | live | sdate | 100 | sdate | sdate | sdate | date | ship_date | | -| fc | live | oseas | 97 | odate | | ssyr | integer | | | -| fc | live | calc_status | 94 | order_status | order_status | calc_status | text | order_status | | -| fc | live | rseas | 99 | rdate | | ssyr | integer | | | -| fc | live | sseas | 101 | sdate | | ssyr | integer | | | -| | | | | | | | | version | | -| | | | | | | | | iter | | -| | | | | | | | | logid | | - -* func: table name of associated data -* fkey: primary key of assoicated dat -* fcol: associated field from the master data table if it is different (oseas would refer to ssyr in fc.perd) -* pretty: display column name (user friendly) -* appcol: parameters that will have to be supplied but the application - * order_date - * ship_date - * customer - * item - * order_stats - * units - * cost - * value - * version (added if missing) - * iter (added if missing) - * logid (added if missing) -* dateref: