diff --git a/deploy/setup.cmd b/deploy/setup.cmd index 1c04b9b..135986d 100644 --- a/deploy/setup.cmd +++ b/deploy/setup.cmd @@ -1,6 +1,6 @@ -"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "DROP DATABASE ubm" -"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "CREATE DATABASE ubm" -"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d ubm -U postgres -f "C:\users\fleet\documents\tps_etl\ubm_schema.sql" +"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "DROP DATABASE ubm2" +"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d postgres -U postgres -c "CREATE DATABASE ubm2" +"C:\PostgreSQL\pg10\bin\psql" -h localhost -p 5433 -d ubm2 -U postgres -f "C:\users\fleet\documents\tps_etl\ubm_schema.sql" "/home/ubuntu/workspace/bigsql/pg10/bin/psql" -h localhost -p 5432 -d postgres -U postgres -c "DROP DATABASE ubm" "/home/ubuntu/workspace/bigsql/pg10/bin/psql" -h localhost -p 5432 -d postgres -U postgres -c "CREATE DATABASE ubm" diff --git a/deploy/ubm_schema.sql b/deploy/ubm_schema.sql index 42b204a..ef7eab3 100644 --- a/deploy/ubm_schema.sql +++ b/deploy/ubm_schema.sql @@ -82,6 +82,76 @@ END; $$; +-- +-- Name: srce_set(text, jsonb); Type: FUNCTION; Schema: tps; Owner: - +-- + +CREATE FUNCTION srce_set(_name text, _defn jsonb) RETURNS jsonb + LANGUAGE plpgsql + AS $_$ + +DECLARE +_cnt int; +_conflict BOOLEAN; +_message jsonb; + +BEGIN + +/* +1. determine if insert or update +2. if update, determine if conflicts exists +3. do merge +*/ + + -------check for transctions already existing under this source----------- + SELECT + COUNT(*) + INTO + _cnt + FROM + tps.trans + WHERE + srce = _name; + + -------set a message------------------------------------------------------ + IF _cnt > 0 THEN + _conflict = TRUE; + --get out of the function somehow + _message = + $$ + { + "message":"transactions already exist under source profile, cannot change the definition" + ,"status":"error" + } + $$::jsonb; + return _message; + END IF; + + /*-----------------schema validation--------------------- + yeah dont feel like it right now + ---------------------------------------------------------*/ + + INSERT INTO + tps.srce + SELECT + _name, _defn + ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE + SET + defn = _defn; + + _message = + $$ + { + "message":"definition set" + ,"status":"success" + } + $$::jsonb; + return _message; + +END; +$_$; + + -- -- Name: jsonb_concat_obj(jsonb); Type: AGGREGATE; Schema: tps; Owner: - -- diff --git a/functions/srce_edit.pgsql b/functions/srce_edit.pgsql index d4926bf..cbfae26 100644 --- a/functions/srce_edit.pgsql +++ b/functions/srce_edit.pgsql @@ -29,7 +29,7 @@ BEGIN IF _cnt > 0 THEN _conflict = TRUE; --get out of the function somehow - _message: = + _message = $$ { "message":"transactions already exist under source profile, cannot change the definition" @@ -47,10 +47,18 @@ BEGIN tps.srce SELECT _name, _defn - ON CONFLICT DO UPDATE + ON CONFLICT ON CONSTRAINT srce_pkey DO UPDATE SET defn = _defn; + _message = + $$ + { + "message":"definition set" + ,"status":"success" + } + $$::jsonb; + return _message; END; $f$