From 6485613ab7b89089720fb69ad84b2c0c4d658a62 Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 14 Feb 2020 14:41:29 -0500 Subject: [PATCH 1/6] add undo route, and include comments --- index.js | 32 ++++++++++++++++++++++++++++++++ route_sql/get_pool.sql | 10 ++++++++-- route_sql/undo.sql | 5 +++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 route_sql/undo.sql diff --git a/index.js b/index.js index 1f617ee..d4bb9b0 100644 --- a/index.js +++ b/index.js @@ -80,6 +80,7 @@ server.get('/get_pool', bodyParser.json(), function(req, res) { console.log(new Date().toISOString() + "-------------------------get pool:----------------------------"); console.log(req.body.quota_rep); sql = sql.replace("rep_replace", req.body.quota_rep); + console.log(sql); Postgres.FirstRow(sql, [], res) }; @@ -164,6 +165,37 @@ server.get('/list_changes', bodyParser.json(), function(req, res) { }; }) +server.get('/undo_change', bodyParser.json(), function(req, res) { + + var sql = ""; + var w = ""; + var c = 1; + var d = 1; + var args = []; + var path = './route_sql/undo.sql'; + + fs.readFile(path, 'utf8', function(err, data) { + if (!err) { + callback(data); + } else { + console.log("fatal error pulling sql file") + callback(err); + } + }); + + var callback = function(arg) { + sql = arg; + + console.log(new Date().toISOString() + "-------------------------undo change:------------------------------") + console.log(req.body); + //parse the where clause into the main sql statement + sql = sql.replace(new RegExp("replace_id", 'g'), JSON.stringify(req.body.logid)) + //execute the sql and send the result + console.log(sql); + Postgres.FirstRow(sql, [], res) + }; +}) + server.post('/addmonth_v', bodyParser.json(), function(req, res) { var sql = ""; diff --git a/route_sql/get_pool.sql b/route_sql/get_pool.sql index 3c9506b..0e68159 100644 --- a/route_sql/get_pool.sql +++ b/route_sql/get_pool.sql @@ -29,14 +29,17 @@ SELECT ,request_season ,request_month ,promo - ,version - ,iter --------values------------------------- ,sum(value_loc) value_loc ,sum(value_usd) value_usd ,sum(cost_loc) cost_loc ,sum(cost_usd) cost_usd ,sum(units) units + ,version + ,iter + ,logid + ,comment + ,module FROM rlarp.osm_pool WHERE @@ -73,6 +76,9 @@ GROUP BY ,promo ,version ,iter + ,logid + ,comment + ,module ) SELECT json_agg(row_to_json(rows)) x diff --git a/route_sql/undo.sql b/route_sql/undo.sql new file mode 100644 index 0000000..2c2b100 --- /dev/null +++ b/route_sql/undo.sql @@ -0,0 +1,5 @@ +WITH +d AS ( +DELETE FROM rlarp.osm_log WHERE id = replace_id RETURNING id +) +SELECT json_agg(row_to_json(d)) x from d \ No newline at end of file From 18558674c0b28fa679a89bad7efd68ca3ed0f094 Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 14 Feb 2020 14:41:51 -0500 Subject: [PATCH 2/6] change key name to message --- route_sql/new_basket.sql | 2 +- route_sql/scale_pd.sql | 2 +- route_sql/scale_vd.sql | 2 +- route_sql/scale_vupd.sql | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 7c748e3..a544a1c 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -332,7 +332,7 @@ SELECT ,'replace_version' "version" ,'replace_source'||' volume' iter ,log.id - ,log.doc->>'comment' "comment" + ,log.doc->>'message' "comment" ,log.doc->>'type' module FROM basemix b diff --git a/route_sql/scale_pd.sql b/route_sql/scale_pd.sql index b119180..8144bee 100644 --- a/route_sql/scale_pd.sql +++ b/route_sql/scale_pd.sql @@ -167,7 +167,7 @@ target AS (select target_increment incr) ,'replace_version' "version" ,'replace_source'||' price' iter ,log.id - ,log.doc->>'comment' "comment" + ,log.doc->>'message' "comment" ,log.doc->>'type' module FROM basemix b diff --git a/route_sql/scale_vd.sql b/route_sql/scale_vd.sql index a285bdb..0710745 100644 --- a/route_sql/scale_vd.sql +++ b/route_sql/scale_vd.sql @@ -196,7 +196,7 @@ target AS (select incr_qty qincr) ,'replace_version' "version" ,'replace_source'||' volume' iter ,log.id - ,log.doc->>'comment' "comment" + ,log.doc->>'message' "comment" ,log.doc->>'type' module FROM basemix b diff --git a/route_sql/scale_vupd.sql b/route_sql/scale_vupd.sql index e7330fe..b2a0e6f 100644 --- a/route_sql/scale_vupd.sql +++ b/route_sql/scale_vupd.sql @@ -195,7 +195,7 @@ target AS (select target_vol vincr, target_prc pincr) ,'replace_version' "version" ,'replace_source'||' volume' iter ,log.id - ,log.doc->>'comment' "comment" + ,log.doc->>'message' "comment" ,log.doc->>'type' module FROM basemix b @@ -274,7 +274,7 @@ FROM ,'replace_version' "version" ,'replace_source'||' price' iter ,log.id - ,log.doc->>'comment' "comment" + ,log.doc->>'message' "comment" ,log.doc->>'type' module FROM volume b From 33041761c6907ebe9e78fe1b73f0ed4063278609 Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 14 Feb 2020 15:42:41 -0500 Subject: [PATCH 3/6] drop rows from both tables when undoing changes --- route_sql/undo.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/route_sql/undo.sql b/route_sql/undo.sql index 2c2b100..e5bc8b0 100644 --- a/route_sql/undo.sql +++ b/route_sql/undo.sql @@ -1,5 +1,8 @@ WITH d AS ( -DELETE FROM rlarp.osm_log WHERE id = replace_id RETURNING id + DELETE FROM rlarp.osm_log WHERE id = replace_id RETURNING id +) +,d_osm AS ( + DELETE FROM rlarp.osm_pool WHERE logid IN (select id from d) ) SELECT json_agg(row_to_json(d)) x from d \ No newline at end of file From db13f3d38cbc89fff3dbdd4928f76da32a55624a Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Fri, 14 Feb 2020 15:52:16 -0500 Subject: [PATCH 4/6] routes that make adjustments need to return comment info --- route_sql/new_basket.sql | 6 ++++++ route_sql/scale_pd.sql | 6 ++++++ route_sql/scale_vd.sql | 6 ++++++ route_sql/scale_vupd.sql | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index a544a1c..94bb824 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -452,6 +452,9 @@ FROM ,promo ,version ,iter + ,logid + ,comment + ,module --------values------------------------- ,sum(value_loc) value_loc ,sum(value_usd) value_usd @@ -492,5 +495,8 @@ FROM ,promo ,version ,iter + ,logid + ,comment + ,module ) SELECT json_agg(row_to_json(insagg)) x from insagg \ No newline at end of file diff --git a/route_sql/scale_pd.sql b/route_sql/scale_pd.sql index 8144bee..442020e 100644 --- a/route_sql/scale_pd.sql +++ b/route_sql/scale_pd.sql @@ -213,6 +213,9 @@ target AS (select target_increment incr) ,promo ,version ,iter + ,logid + ,comment + ,module --------values------------------------- ,sum(value_loc) value_loc ,sum(value_usd) value_usd @@ -253,5 +256,8 @@ target AS (select target_increment incr) ,promo ,version ,iter + ,logid + ,comment + ,module ) SELECT json_agg(row_to_json(insagg)) x from insagg diff --git a/route_sql/scale_vd.sql b/route_sql/scale_vd.sql index 0710745..db88757 100644 --- a/route_sql/scale_vd.sql +++ b/route_sql/scale_vd.sql @@ -240,6 +240,9 @@ FROM ,promo ,version ,iter + ,logid + ,comment + ,module --------values------------------------- ,sum(value_loc) value_loc ,sum(value_usd) value_usd @@ -280,5 +283,8 @@ FROM ,promo ,version ,iter + ,logid + ,comment + ,module ) SELECT json_agg(row_to_json(insagg)) x from insagg \ No newline at end of file diff --git a/route_sql/scale_vupd.sql b/route_sql/scale_vupd.sql index b2a0e6f..9641bab 100644 --- a/route_sql/scale_vupd.sql +++ b/route_sql/scale_vupd.sql @@ -320,6 +320,9 @@ FROM ,promo ,version ,iter + ,logid + ,comment + ,module --------values------------------------- ,sum(value_loc) value_loc ,sum(value_usd) value_usd @@ -360,5 +363,8 @@ FROM ,promo ,version ,iter + ,logid + ,comment + ,module ) SELECT json_agg(row_to_json(insagg)) x from insagg From 6774a2fdff9fd89e263c972ba1af0bd5f040c47c Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 14 Feb 2020 17:00:06 -0500 Subject: [PATCH 5/6] default load as not null --- index.js | 2 +- route_sql/build/build_fcpool.sql | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d4bb9b0..12d8e1b 100644 --- a/index.js +++ b/index.js @@ -129,7 +129,7 @@ server.get('/scenario_package', bodyParser.json(), function(req, res) { //parse the where clause into the main sql statement sql = sql.replace(new RegExp("where_clause", 'g'), w) //execute the sql and send the result - //console.log(sql); + console.log(sql); Postgres.FirstRow(sql, [], res) }; }) diff --git a/route_sql/build/build_fcpool.sql b/route_sql/build/build_fcpool.sql index 77440a2..8629732 100644 --- a/route_sql/build/build_fcpool.sql +++ b/route_sql/build/build_fcpool.sql @@ -101,8 +101,8 @@ SELECT ,version ,iter ,null::int logid - ,null::text "comment" - ,null::text module + ,''::text "comment" + ,''::text module FROM rlarp.osmf_dev o LEFT OUTER JOIN lgdat.cust bc ON From 7635380ccc21f2a4ed291df3d558991ce0bc33ea Mon Sep 17 00:00:00 2001 From: Trowbridge Date: Fri, 14 Feb 2020 17:00:44 -0500 Subject: [PATCH 6/6] ensure not to load null comments --- route_sql/new_basket.sql | 2 +- route_sql/scale_pd.sql | 2 +- route_sql/scale_vd.sql | 2 +- route_sql/scale_vupd.sql | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index 94bb824..1ed7f36 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -332,7 +332,7 @@ SELECT ,'replace_version' "version" ,'replace_source'||' volume' iter ,log.id - ,log.doc->>'message' "comment" + ,COALESCE(log.doc->>'message','') "comment" ,log.doc->>'type' module FROM basemix b diff --git a/route_sql/scale_pd.sql b/route_sql/scale_pd.sql index 442020e..1638e70 100644 --- a/route_sql/scale_pd.sql +++ b/route_sql/scale_pd.sql @@ -167,7 +167,7 @@ target AS (select target_increment incr) ,'replace_version' "version" ,'replace_source'||' price' iter ,log.id - ,log.doc->>'message' "comment" + ,COALESCE(log.doc->>'message','') "comment" ,log.doc->>'type' module FROM basemix b diff --git a/route_sql/scale_vd.sql b/route_sql/scale_vd.sql index db88757..9d09f1a 100644 --- a/route_sql/scale_vd.sql +++ b/route_sql/scale_vd.sql @@ -196,7 +196,7 @@ target AS (select incr_qty qincr) ,'replace_version' "version" ,'replace_source'||' volume' iter ,log.id - ,log.doc->>'message' "comment" + ,COALESCE(log.doc->>'message','') "comment" ,log.doc->>'type' module FROM basemix b diff --git a/route_sql/scale_vupd.sql b/route_sql/scale_vupd.sql index 9641bab..cdfdd7a 100644 --- a/route_sql/scale_vupd.sql +++ b/route_sql/scale_vupd.sql @@ -195,7 +195,7 @@ target AS (select target_vol vincr, target_prc pincr) ,'replace_version' "version" ,'replace_source'||' volume' iter ,log.id - ,log.doc->>'message' "comment" + ,COALESCE(log.doc->>'message','') "comment" ,log.doc->>'type' module FROM basemix b @@ -274,7 +274,7 @@ FROM ,'replace_version' "version" ,'replace_source'||' price' iter ,log.id - ,log.doc->>'message' "comment" + ,COALESCE(log.doc->>'message','') "comment" ,log.doc->>'type' module FROM volume b