Compare commits

..

No commits in common. "a859ffa91a143331e11745e9b577b920c1bf88b7" and "6462e742d9798ccca37a6b66c92718f3d210e3b3" have entirely different histories.

3 changed files with 18 additions and 16 deletions

View File

@ -1,14 +1,16 @@
* setup postgres db with a username and password and database
* add this to .bashrc to quickly invoke command line connection `export PGD="psql -U ptrowbridge -d ubm -p 5433 -h 192.168.1.110"`
## worked on so far
setup
----------------------------------------------------------------------------------------------------------------------------------------------------
* setup the application tables `$PGD -f setup_sql/schema.sql`
* create a table of data to forecast
* edit `target_info.sql` to reflect the name of the table from previous step
* `$PGD -f setup_sql/target_info.sql` to populate the meta table
* fill out the `target_meta` table in the database to model the forecast table
* `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
the basic assumption is a single sales table is available to work with that has a lot of related data that came from master data tables originally.
the goal then is to break that back apart to whatever degree is necessary.
* _**run**_ `schema.sql` and `perd.sql` to setup basic tables
* create a table fc.live as copied from target (will need to have columns `version` and `iter` added if not existing)
* _**run**_ `target_info.sql` to populate the `fc.target_meta` table that holds all the columns and their roles
* fill in flags on table `fc.target_meta` to show how the data is related
* _**run**_ `build_master_tables.sql` to generate foreign key based master data
routes
----------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -49,6 +49,8 @@ WHERE
dtype = 'date'
AND fkey IS NOT NULL;
CREATE TABLE IF NOT EXISTS fc.sql(cmd text PRIMARY KEY, t text );
-------------------------------build a column list-----------------------------------------
SELECT
string_agg('o.'||format('%I',cname),E'\n ,' ORDER BY opos ASC)
@ -105,11 +107,11 @@ FROM
WHERE
(
--base period orders booked....
$$||format('%I',_order_date)||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date
$$||_order_date||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date
--...or any open orders currently booked before cutoff....
OR ($$||format('%I',_order_status)||$$ IN ('app_openstatus_code') and $$||format('%I',_order_date)||$$ <= 'app_openorder_cutoff'::date)
OR ($$||_order_status||$$ IN (app_openstatus_code) and $$||_order_date||$$ <= 'app_openorder_cutoff'::date)
--...or anything that shipped in that period
OR ($$||format('%I',_ship_date)||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date)
OR ($$||_ship_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
$$::text

View File

@ -1,4 +1,4 @@
CREATE SCHEMA IF NOT EXISTS fc;
--assumes schema fc already exists
--DROP TABLE IF EXISTS fc.target_meta;
CREATE TABLE IF NOT EXISTS fc.target_meta (
@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS 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';
@ -35,5 +35,3 @@ CREATE TABLE IF NOT EXISTS fc.log (
);
COMMENT ON TABLE fc.log IS 'forecast change log';
CREATE TABLE IF NOT EXISTS fc.sql(cmd text PRIMARY KEY, t text );