From 4dd71057f40dab9a69deddf77edf2d53f4eccba6 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 28 Apr 2022 01:09:26 -0400 Subject: [PATCH] move baseline route sql to table only mode --- routes/baseline/baseline.sql | 119 ------------------ routes/baseline/generate_route_sql.sh | 2 +- .../04_gen_baseline.sql} | 0 3 files changed, 1 insertion(+), 120 deletions(-) delete mode 100644 routes/baseline/baseline.sql rename routes/{baseline/gen_baseline.sql => setup_sql/04_gen_baseline.sql} (100%) diff --git a/routes/baseline/baseline.sql b/routes/baseline/baseline.sql deleted file mode 100644 index 15403e1..0000000 --- a/routes/baseline/baseline.sql +++ /dev/null @@ -1,119 +0,0 @@ -DELETE FROM tpsv.dcard WHERE app_version = 'app_forecast_name'; -WITH -req AS (SELECT $$app_req$$::jsonb j) -,ilog AS ( - INSERT INTO - fc.log (doc) - SELECT - req.j - FROM - req - RETURNING * -) -,baseline AS ( -SELECT - null::integer AS id - ,null::integer AS logid - ,o."Trans. Date" - ,o."Post Date" - ,o."Description" - ,sum(o."Amount") AS "Amount" - ,o."Category" - ,o."Party" - ,o."Reason" - ,sum(o.app_units) AS app_units - ,'app_forecast_name' AS app_version - ,'baseline' AS app_iter - ,(SELECT id FROM ilog) AS app_logid -FROM - tpsv.dcard o -WHERE - ( - --base period orders booked.... - "Trans. Date" BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date - --...or any open orders currently booked before cutoff.... - OR ("Description" IN (app_openstatus_code) and "Trans. Date" <= 'app_openorder_cutoff'::date) - --...or anything that shipped in that period - OR ("Post Date" BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date) - ) - --be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships -GROUP BY - o."Trans. Date" - ,o."Post Date" - ,o."Description" - ,o."Category" - ,o."Party" - ,o."Reason" -UNION ALL -SELECT - null::integer AS id - ,null::integer AS logid - ,o."Trans. Date" + interval '1 year' AS "Trans. Date" - ,o."Post Date" + interval '1 year' AS "Post Date" - ,o."Description" - ,sum(o."Amount") AS "Amount" - ,o."Category" - ,o."Party" - ,o."Reason" - ,sum(o.app_units) AS app_units - ,'app_forecast_name' AS app_version - ,'baseline' AS app_iter - ,(SELECT id FROM ilog) AS app_logid -FROM - tpsv.dcard o - LEFT OUTER JOIN fc.perd tdate ON - (o."Trans. Date" + interval '1 year' )::date <@ tdate.drange - LEFT OUTER JOIN fc.perd pdate ON - (o."Post Date" + interval '1 year' )::date <@ pdate.drange -WHERE - "Trans. Date" BETWEEN 'app_plug_fromdate'::date AND 'app_plug_todate'::date - --be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships -GROUP BY - o."Trans. Date" - ,o."Post Date" - ,o."Description" - ,o."Category" - ,o."Party" - ,o."Reason") -,incr AS ( -SELECT - null::integer AS id - ,null::integer AS logid - ,o."Trans. Date" + interval '1 year' AS "Trans. Date" - ,o."Post Date" + interval '1 year' AS "Post Date" - ,o."Description" - ,sum(o."Amount") AS "Amount" - ,o."Category" - ,o."Party" - ,o."Reason" - ,sum(o.app_units) AS app_units - ,'app_forecast_name' AS app_version - ,'baseline' AS app_iter - ,(SELECT id FROM ilog) AS app_logid -FROM - baseline o -LEFT OUTER JOIN fc.perd tdate ON - (o."Trans. Date" + interval '1 year' )::date <@ tdate.drange - LEFT OUTER JOIN fc.perd pdate ON - (o."Post Date" + interval '1 year' )::date <@ pdate.drange -GROUP BY - o."Trans. Date" - ,o."Post Date" - ,o."Description" - ,o."Category" - ,o."Party" - ,o."Reason" -) -,ins AS ( -INSERT INTO - tpsv.dcard -SELECT - * -FROM - incr i -WHERE - i."Trans. Date" >= 'app_first_forecast_date'::date - OR i."Post Date" >= 'app_first_forecast_date'::date -RETURNING * -) -SELECT COUNT(*) num_rows FROM ins diff --git a/routes/baseline/generate_route_sql.sh b/routes/baseline/generate_route_sql.sh index f5b4231..d3d5b01 100755 --- a/routes/baseline/generate_route_sql.sh +++ b/routes/baseline/generate_route_sql.sh @@ -1,4 +1,4 @@ # execure the sql for baseline which builds the sql and inserts into a table -$PG -f routes/baseline/gen_baseline.sql +#$PG -f routes/baseline/gen_baseline.sql # pull the sql out of the table and write it to route directory $PG -c "SELECT t FROM fc.sql WHERE cmd = 'baseline'" -t -A -o routes/baseline/baseline.sql diff --git a/routes/baseline/gen_baseline.sql b/routes/setup_sql/04_gen_baseline.sql similarity index 100% rename from routes/baseline/gen_baseline.sql rename to routes/setup_sql/04_gen_baseline.sql