diff --git a/deploy/ubm_schema.sql b/deploy/ubm_schema.sql index 8a617fa..20ca8f1 100644 --- a/deploy/ubm_schema.sql +++ b/deploy/ubm_schema.sql @@ -50,7 +50,6 @@ COMMENT ON TYPE tps."DCARD" IS 'Discover Card'; - -- -- Name: DMAPI; Type: TYPE; Schema: tps; Owner: - -- @@ -60,6 +59,41 @@ CREATE TYPE tps."DMAPI" AS ( ); +-- +-- Name: WMPD; Type: TYPE; Schema: tps; Owner: - +-- + +CREATE TYPE tps."WMPD" AS ( + "Carrier" text, + "SCAC" text, + "Mode" text, + "Pro #" text, + "B/L" text, + "Pd Amt" numeric, + "Loc#" text, + "Pcs" numeric, + "Wgt" numeric, + "Chk#" numeric, + "Pay Dt" date, + "Acct #" text, + "I/O" text, + "Sh Nm" text, + "Sh City" text, + "Sh St" text, + "Sh Zip" text, + "Cons Nm" text, + "D City " text, + "D St" text, + "D Zip" text, + "Sh Dt" date, + "Inv Dt" date, + "Customs Entry#" text, + "Miles" numeric, + "Frt Class" text, + "Master B/L" text +); + + -- -- Name: dcard; Type: TYPE; Schema: tps; Owner: - -- @@ -1067,10 +1101,10 @@ $_$; -- --- Name: srce_set(text, jsonb); Type: FUNCTION; Schema: tps; Owner: - +-- Name: srce_set(jsonb); Type: FUNCTION; Schema: tps; Owner: - -- -CREATE FUNCTION tps.srce_set(_name text, _defn jsonb) RETURNS jsonb +CREATE FUNCTION tps.srce_set(_defn jsonb) RETURNS jsonb LANGUAGE plpgsql AS $_$ @@ -1097,7 +1131,7 @@ BEGIN FROM tps.srce WHERE - srce = _name; + srce = _defn->>'name'; -------check for transctions already existing under this source----------- SELECT @@ -1107,7 +1141,7 @@ BEGIN FROM tps.trans WHERE - srce = _name; + srce = _defn->>'name'; --if there are transaction already and the schema is different stop-------- IF _cnt > 0 THEN @@ -1133,14 +1167,14 @@ BEGIN INSERT INTO tps.srce SELECT - _name, _defn + _defn->>'name', _defn ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE SET defn = _defn; ------------------drop existing type----------------------------------------- - EXECUTE format('DROP TYPE IF EXISTS tps.%I',_name); + EXECUTE format('DROP TYPE IF EXISTS tps.%I',_defn->>'name'); ------------------create new type-------------------------------------------- @@ -1153,15 +1187,15 @@ BEGIN --unwrap the schema definition array LEFT JOIN LATERAL jsonb_populate_recordset(null::tps.srce_defn_schema, defn->'schema') prs ON TRUE WHERE - srce = _name + srce = _defn->>'name' GROUP BY srce; - RAISE NOTICE 'CREATE TYPE tps.% AS (%)',_name,_sql; + RAISE NOTICE 'CREATE TYPE tps.% AS (%)',_defn->>'name',_sql; - EXECUTE format('CREATE TYPE tps.%I AS (%s)',_name,_sql); + EXECUTE format('CREATE TYPE tps.%I AS (%s)',_defn->>'name',_sql); - EXECUTE format('COMMENT ON TYPE tps.%I IS %L',_name,(_defn->>'description')); + EXECUTE format('COMMENT ON TYPE tps.%I IS %L',_defn->>'name',(_defn->>'description')); ----------------set message----------------------------------------------------- diff --git a/functions/srce_set.sql b/functions/srce_set.sql index db5ec32..8dccc52 100644 --- a/functions/srce_set.sql +++ b/functions/srce_set.sql @@ -1,5 +1,5 @@ -CREATE OR REPLACE FUNCTION tps.srce_set(_name text, _defn jsonb) RETURNS jsonb +CREATE OR REPLACE FUNCTION tps.srce_set(_defn jsonb) RETURNS jsonb AS $f$ DECLARE @@ -25,7 +25,7 @@ BEGIN FROM tps.srce WHERE - srce = _name; + srce = _defn->>'name'; -------check for transctions already existing under this source----------- SELECT @@ -35,7 +35,7 @@ BEGIN FROM tps.trans WHERE - srce = _name; + srce = _defn->>'name'; --if there are transaction already and the schema is different stop-------- IF _cnt > 0 THEN @@ -61,14 +61,14 @@ BEGIN INSERT INTO tps.srce SELECT - _name, _defn + _defn->>'name', _defn ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE SET defn = _defn; ------------------drop existing type----------------------------------------- - EXECUTE format('DROP TYPE IF EXISTS tps.%I',_name); + EXECUTE format('DROP TYPE IF EXISTS tps.%I',_defn->>'name'); ------------------create new type-------------------------------------------- @@ -81,15 +81,15 @@ BEGIN --unwrap the schema definition array LEFT JOIN LATERAL jsonb_populate_recordset(null::tps.srce_defn_schema, defn->'schema') prs ON TRUE WHERE - srce = _name + srce = _defn->>'name' GROUP BY srce; - RAISE NOTICE 'CREATE TYPE tps.% AS (%)',_name,_sql; + RAISE NOTICE 'CREATE TYPE tps.% AS (%)',_defn->>'name',_sql; - EXECUTE format('CREATE TYPE tps.%I AS (%s)',_name,_sql); + EXECUTE format('CREATE TYPE tps.%I AS (%s)',_defn->>'name',_sql); - EXECUTE format('COMMENT ON TYPE tps.%I IS %L',_name,(_defn->>'description')); + EXECUTE format('COMMENT ON TYPE tps.%I IS %L',_defn->>'name',(_defn->>'description')); ----------------set message-----------------------------------------------------