use proper data type for app columns, include master table for app columns
This commit is contained in:
		
							parent
							
								
									b47630cf61
								
							
						
					
					
						commit
						a657106bf5
					
				| @ -48,7 +48,8 @@ BEGIN | ||||
|         INSERT INTO  | ||||
|             fc.target_meta | ||||
|         SELECT  | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, data_type, 'units', null::text | ||||
|             --schema        tname        cname        opos            func         fkey        fcol        dtype         appcol    pretty | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, 'numeric' , 'units', null::text | ||||
|         FROM  | ||||
|             information_schema.columns | ||||
|         WHERE | ||||
| @ -63,7 +64,7 @@ BEGIN | ||||
|         INSERT INTO  | ||||
|             fc.target_meta | ||||
|         SELECT  | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, data_type, 'version', null::text | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, 'text', 'version', null::text | ||||
|         FROM  | ||||
|             information_schema.columns | ||||
|         WHERE | ||||
| @ -78,7 +79,7 @@ BEGIN | ||||
|         INSERT INTO  | ||||
|             fc.target_meta | ||||
|         SELECT  | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, data_type, 'iter', null::text | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text,  'text' , 'iter', null::text | ||||
|         FROM  | ||||
|             information_schema.columns | ||||
|         WHERE | ||||
| @ -93,7 +94,7 @@ BEGIN | ||||
|         INSERT INTO  | ||||
|             fc.target_meta | ||||
|         SELECT  | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, data_type, 'logid', null::text | ||||
|             table_schema, table_name, column_name, ordinal_position, null::text, null::text, null::text, 'bigint' , 'logid', null::text | ||||
|         FROM  | ||||
|             information_schema.columns | ||||
|         WHERE | ||||
|  | ||||
| @ -29,6 +29,38 @@ 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)'; | ||||
| COMMENT ON COLUMN fc.target_meta.pretty IS 'the presentation name of the column'; | ||||
| 
 | ||||
| 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); | ||||
| 
 | ||||
| CREATE TABLE IF NOT EXISTS fc.log  ( | ||||
|     id int GENERATED ALWAYS AS IDENTITY | ||||
|     ,doc jsonb | ||||
|  | ||||
| @ -9,7 +9,7 @@ SELECT | ||||
|     ,ordinal_position | ||||
|     ,null::text func | ||||
|     ,null::text fkey        --foreign key to a master table | ||||
|     ,column_name fcol | ||||
|     ,null::text fcol | ||||
|     ,data_type::text dtype | ||||
|     ,null::text appcol | ||||
|     ,null::text pretty | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user