include previos changes into the main deployment script
This commit is contained in:
parent
8a7a597cf4
commit
ca0a3d107a
@ -168,7 +168,35 @@ DECLARE
|
|||||||
_MESSAGE_TEXT text;
|
_MESSAGE_TEXT text;
|
||||||
_PG_EXCEPTION_DETAIL text;
|
_PG_EXCEPTION_DETAIL text;
|
||||||
_PG_EXCEPTION_HINT text;
|
_PG_EXCEPTION_HINT text;
|
||||||
|
_rebuild BOOLEAN;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
|
---------test if anythign is changing--------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IF _defn = (SELECT defn FROM tps.srce WHERE srce = _defn->>'name') THEN
|
||||||
|
_message:=
|
||||||
|
(
|
||||||
|
$$
|
||||||
|
{
|
||||||
|
"status":"complete",
|
||||||
|
"message":"source was not different no action taken"
|
||||||
|
}
|
||||||
|
$$::jsonb
|
||||||
|
);
|
||||||
|
RETURN _message;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
---------if the constraint definition is changing, rebuild for existing records---------------------------------------------------
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
NOT (_defn->'constraint' = (SELECT defn->'constraint' FROM tps.srce WHERE srce = _defn->>'name'))
|
||||||
|
INTO
|
||||||
|
_rebuild;
|
||||||
|
|
||||||
|
RAISE NOTICE '%',_rebuild::text;
|
||||||
|
|
||||||
|
---------do merge-----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
tps.srce (srce, defn, hist)
|
tps.srce (srce, defn, hist)
|
||||||
SELECT
|
SELECT
|
||||||
@ -196,7 +224,52 @@ BEGIN
|
|||||||
,'{0,effective,1}'::text[]
|
,'{0,effective,1}'::text[]
|
||||||
,to_jsonb(CURRENT_TIMESTAMP)
|
,to_jsonb(CURRENT_TIMESTAMP)
|
||||||
);
|
);
|
||||||
|
--rebuild constraint key if necessary---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IF _rebuild THEN
|
||||||
|
WITH
|
||||||
|
rebuild AS (
|
||||||
|
SELECT
|
||||||
|
j.srce
|
||||||
|
,j.rec
|
||||||
|
,j.id
|
||||||
|
--aggregate back to the record since multiple paths may be listed in the constraint
|
||||||
|
,tps.jsonb_concat_obj(
|
||||||
|
jsonb_build_object(
|
||||||
|
--the new json key is the path itself
|
||||||
|
cons.path->>0
|
||||||
|
,j.rec#>((cons.path->>0)::text[])
|
||||||
|
)
|
||||||
|
) json_key
|
||||||
|
FROM
|
||||||
|
tps.trans j
|
||||||
|
INNER JOIN tps.srce s ON
|
||||||
|
s.srce = j.srce
|
||||||
|
JOIN LATERAL jsonb_array_elements(s.defn->'constraint') WITH ORDINALITY cons(path, seq) ON TRUE
|
||||||
|
WHERE
|
||||||
|
s.srce = _defn->>'name'
|
||||||
|
GROUP BY
|
||||||
|
j.rec
|
||||||
|
,j.id
|
||||||
|
)
|
||||||
|
UPDATE
|
||||||
|
tps.trans t
|
||||||
|
SET
|
||||||
|
ic = r.json_key
|
||||||
|
FROM
|
||||||
|
rebuild r
|
||||||
|
WHERE
|
||||||
|
t.id = r.id;
|
||||||
|
_message:=
|
||||||
|
(
|
||||||
|
$$
|
||||||
|
{
|
||||||
|
"status":"complete",
|
||||||
|
"message":"source set and constraint rebuilt on existing records"
|
||||||
|
}
|
||||||
|
$$::jsonb
|
||||||
|
);
|
||||||
|
ELSE
|
||||||
_message:=
|
_message:=
|
||||||
(
|
(
|
||||||
$$
|
$$
|
||||||
@ -206,8 +279,12 @@ BEGIN
|
|||||||
}
|
}
|
||||||
$$::jsonb
|
$$::jsonb
|
||||||
);
|
);
|
||||||
|
END IF;
|
||||||
|
|
||||||
RETURN _message;
|
RETURN _message;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXCEPTION WHEN OTHERS THEN
|
EXCEPTION WHEN OTHERS THEN
|
||||||
GET STACKED DIAGNOSTICS
|
GET STACKED DIAGNOSTICS
|
||||||
_MESSAGE_TEXT = MESSAGE_TEXT,
|
_MESSAGE_TEXT = MESSAGE_TEXT,
|
||||||
@ -225,7 +302,7 @@ BEGIN
|
|||||||
RETURN _message;
|
RETURN _message;
|
||||||
END;
|
END;
|
||||||
$f$
|
$f$
|
||||||
LANGUAGE plpgsql;
|
LANGUAGE plpgsql
|
||||||
|
|
||||||
-----generate sql to create select based on schema
|
-----generate sql to create select based on schema
|
||||||
DROP FUNCTION IF EXISTS tps.build_srce_view_sql(text, text);
|
DROP FUNCTION IF EXISTS tps.build_srce_view_sql(text, text);
|
||||||
|
Loading…
Reference in New Issue
Block a user