diff --git a/readme.md b/readme.md index e60ac9a..18d61c3 100644 --- a/readme.md +++ b/readme.md @@ -51,5 +51,6 @@ running problem list - [ ] there is not currently any initial grouping to limit excess data from all the document# scenarios * general - [ ] clean up SQL generation to prevent injection - - [ ] **the sales data has to have a column for module and change ID, live sales data isn't going to work well** - [ ] how to handle a target value adjustment, which currency is it in? + - [ ] **the sales data has to have a column for module and change ID, live sales data isn't going to work well** + - [ ] need to target the live sales data, build build a whole new table to use it plus add version columns diff --git a/routes/scale/gen_scale.sql b/routes/scale/gen_scale.sql index 77e331d..dc47225 100644 --- a/routes/scale/gen_scale.sql +++ b/routes/scale/gen_scale.sql @@ -111,6 +111,14 @@ vscale AS ( FROM basemix ) +,ilog AS ( + INSERT INTO + fc.log (doc) + SELECT + req.j + FROM + req +) ,volume AS ( SELECT $$||_clist_vol||$$ diff --git a/setup_sql/schema.sql b/setup_sql/schema.sql index dfab167..2859997 100644 --- a/setup_sql/schema.sql +++ b/setup_sql/schema.sql @@ -1,7 +1,7 @@ --assumes schema fc already exists -DROP TABLE IF EXISTS fc.target_meta; -CREATE TABLE fc.target_meta ( +--DROP TABLE IF EXISTS fc.target_meta; +CREATE TABLE IF NOT EXISTS fc.target_meta ( tname text ,cname text ,opos int @@ -15,7 +15,7 @@ CREATE TABLE fc.target_meta ( ); --ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk; -ALTER TABLE fc.target_meta ADD CONSTRAINT target_meta_pk PRIMARY KEY (tname, cname); +ALTER TABLE fc.target_meta ADD CONSTRAINT IF NOT EXISTS target_meta_pk PRIMARY KEY (tname, cname); COMMENT ON TABLE fc.target_meta IS 'target table layout info'; COMMENT ON COLUMN fc.target_meta.tname IS 'schema.table_name of target sales data table'; @@ -28,3 +28,10 @@ COMMENT ON COLUMN fc.target_meta.dtype IS 'data type of the sales table column'; COMMENT ON COLUMN fc.target_meta.mastcol IS 'associated field from the master data table if it is different (oseas would refer to ssyr in fc.perd)'; COMMENT ON COLUMN fc.target_meta.appcol IS 'supply column name to be used for application variables - (specifcy the order date column)'; COMMENT ON COLUMN fc.target_meta.dateref IS 'reference to the relevant hard coded perd table column for dates'; + +CREATE TABLE IF NOT EXISTS fc.log ( + id int GENERATED ALWAYS AS IDENTITY + ,doc jsonb +); + +COMMENT ON TABLE fc.log IS 'forecast change log';