diff --git a/deploy/setup.sql b/deploy/setup.sql index d0ad89c..87e86da 100644 --- a/deploy/setup.sql +++ b/deploy/setup.sql @@ -51,7 +51,8 @@ CREATE TABLE tps.map_rm ( srce text NOT NULL, target text NOT NULL, regex jsonb, - seq integer NOT NULL + seq integer NOT NULL, + hist jsonb ); COMMENT ON TABLE tps.map_rm IS 'regex map instructions'; diff --git a/interface/map_def/srce_map_def_set.sql b/interface/map_def/srce_map_def_set.sql index 257fe5e..5127912 100644 --- a/interface/map_def/srce_map_def_set.sql +++ b/interface/map_def/srce_map_def_set.sql @@ -15,15 +15,36 @@ BEGIN INSERT INTO tps.map_rm SELECT + --data source _defn->>'srce' + --map name ,_defn->>'name' + --map definition ,_defn + --map aggregation sequence ,_defn->>'sequence' + --history definition + ,jsonb_build_object( + 'hist_defn',_defn + ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) + ) || '[]'::jsonb ON CONFLICT ON CONSTRAINT map_rm_pk DO UPDATE SET srce = _defn->>'srce' ,target = _defn->>'name' ,regex = _defn - ,seq = _defn->>'sequence'; + ,seq = _defn->>'sequence' + ,hist = + --the new definition going to position -0- + jsonb_build_object( + 'hist_defn',_defn + ,'effective',jsonb_build_array(CURRENT_TIMESTAMP,null::timestamptz) + ) + --the previous definition, set upper bound of effective range which was previously null + || jsonb_set( + map_rm.hist + ,'{0,effective,1}'::text[] + ,to_jsonb(CURRENT_TIMESTAMP) + ); EXCEPTION WHEN OTHERS THEN