2022-04-03 00:50:49 -04:00
|
|
|
CREATE SCHEMA IF NOT EXISTS fc;
|
2020-10-22 01:22:40 -04:00
|
|
|
|
2020-12-08 01:30:02 -05:00
|
|
|
--DROP TABLE IF EXISTS fc.target_meta;
|
|
|
|
CREATE TABLE IF NOT EXISTS fc.target_meta (
|
2022-04-06 01:52:18 -04:00
|
|
|
schema text
|
|
|
|
,tname text
|
2020-11-09 23:20:46 -05:00
|
|
|
,cname text
|
|
|
|
,opos int
|
|
|
|
,func text
|
|
|
|
,fkey text
|
2022-04-06 01:52:18 -04:00
|
|
|
,fcol text
|
2020-11-09 23:20:46 -05:00
|
|
|
,dtype text
|
|
|
|
,appcol text
|
2022-04-06 01:52:18 -04:00
|
|
|
,pretty text
|
2020-10-22 01:22:40 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
--ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk;
|
2022-04-06 01:52:18 -04:00
|
|
|
ALTER TABLE fc.target_meta ADD CONSTRAINT target_meta_pk PRIMARY KEY (schema, tname, cname);
|
2020-10-22 01:22:40 -04:00
|
|
|
|
|
|
|
COMMENT ON TABLE fc.target_meta IS 'target table layout info';
|
2022-04-06 01:52:18 -04:00
|
|
|
COMMENT ON COLUMN fc.target_meta.schema IS 'schema of target sales data table';
|
|
|
|
COMMENT ON COLUMN fc.target_meta.tname IS 'table_name of target sales data table';
|
2020-11-05 23:50:02 -05:00
|
|
|
COMMENT ON COLUMN fc.target_meta.cname IS 'column name';
|
|
|
|
COMMENT ON COLUMN fc.target_meta.opos IS 'ordinal position of column';
|
|
|
|
COMMENT ON COLUMN fc.target_meta.func IS 'a functional entity (like customer, part number) that master tables will be build from';
|
2022-04-06 01:52:18 -04:00
|
|
|
COMMENT ON COLUMN fc.target_meta.fcol IS 'associated field from the master data table if it is different (oseas would refer to ssyr in fc.perd)';
|
2020-11-05 23:50:02 -05:00
|
|
|
COMMENT ON COLUMN fc.target_meta.fkey IS 'primary key for functional entity';
|
|
|
|
COMMENT ON COLUMN fc.target_meta.dtype IS 'data type of the sales table column';
|
|
|
|
COMMENT ON COLUMN fc.target_meta.appcol IS 'supply column name to be used for application variables - (specifcy the order date column)';
|
2022-04-06 01:52:18 -04:00
|
|
|
COMMENT ON COLUMN fc.target_meta.pretty IS 'the presentation name of the column';
|
2020-12-08 01:30:02 -05:00
|
|
|
|
2022-04-12 22:52:42 -04:00
|
|
|
CREATE TABLE IF NOT EXISTS fc.appcols (
|
|
|
|
col text,
|
|
|
|
dtype text,
|
|
|
|
required boolean,
|
|
|
|
dflt text
|
|
|
|
);
|
|
|
|
ALTER TABLE fc.appcols DROP CONSTRAINT IF EXISTS appcols_pkey CASCADE;
|
|
|
|
ALTER TABLE fc.appcols ADD CONSTRAINT appcols_pkey PRIMARY KEY (col, dtype);
|
|
|
|
COMMENT ON TABLE fc.appcols IS 'hard-coded columns names searched for by the application';
|
|
|
|
INSERT INTO
|
|
|
|
fc.appcols (col, dtype, required, dflt)
|
|
|
|
VALUES
|
|
|
|
('value' ,'numeric',true, null),
|
|
|
|
('cost' ,'numeric',true, '0'),
|
|
|
|
('units' ,'numeric',true, '0'),
|
|
|
|
('order_date' ,'date' ,true, null),
|
|
|
|
('ship_date' ,'date' ,false, null),
|
|
|
|
('order_status' ,'text' ,true, 'CLOSED'),
|
|
|
|
('version' ,'text' ,true, 'ACTUALS'),
|
|
|
|
('iter' ,'text' ,true, 'ACTUALS'),
|
|
|
|
('logid' ,'bigint' ,true, null),
|
|
|
|
('tag' ,'text' ,true, null),
|
|
|
|
('comment' ,'text' ,true, null),
|
|
|
|
('customer' ,'text' ,false, null),
|
|
|
|
('item' ,'text' ,false, null)
|
|
|
|
ON CONFLICT ON CONSTRAINT appcols_pkey DO UPDATE SET
|
|
|
|
dtype = EXCLUDED.dtype
|
|
|
|
,required = EXCLUDED.required
|
|
|
|
,dflt = EXCLUDED.dflt;
|
|
|
|
|
|
|
|
ALTER TABLE fc.target_meta ADD CONSTRAINT fk_appcol FOREIGN KEY (appcol,dtype) REFERENCES fc.appcols(col, dtype);
|
|
|
|
|
2020-12-08 01:30:02 -05:00
|
|
|
CREATE TABLE IF NOT EXISTS fc.log (
|
|
|
|
id int GENERATED ALWAYS AS IDENTITY
|
|
|
|
,doc jsonb
|
|
|
|
);
|
|
|
|
|
|
|
|
COMMENT ON TABLE fc.log IS 'forecast change log';
|
2022-04-03 00:50:49 -04:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS fc.sql(cmd text PRIMARY KEY, t text );
|