-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed instance update to reflect various json merge needs (#359)
* Changed instance update to reflect various json merge needs. Cases: - Process: Insert complete json - Substatus: Insert complete json - Status: Merge propertis based on updateProperties in repo api - CompleteConfirmations: Merge properties - Datavalues: Merge properties - PresentationTexts: Merge properties - Other top level properties (lastchanged and lastchangedby): Merge properties - "Complications": Process and Substatus might be combined, and the different combinations must be treated separately * Changed property of appsettings.json to "copy allways" --------- Co-authored-by: Henning Normann <h.normann@accenture.com>
- Loading branch information
1 parent
c42e19b
commit 83f7979
Showing
6 changed files
with
279 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
src/Storage/Migration/v0.06/01-functions-and-procedures.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
CREATE OR REPLACE FUNCTION storage.updateinstance_v2( | ||
_alternateid UUID, | ||
_toplevelsimpleprops JSONB, | ||
_datavalues JSONB, | ||
_completeconfirmations JSONB, | ||
_presentationtexts JSONB, | ||
_status JSONB, | ||
_substatus JSONB, | ||
_process JSONB, | ||
_lastchanged TIMESTAMPTZ, | ||
_taskid TEXT) | ||
RETURNS TABLE (updatedInstance JSONB) | ||
LANGUAGE 'plpgsql' | ||
AS $BODY$ | ||
BEGIN | ||
IF _datavalues IS NOT NULL THEN | ||
RETURN QUERY | ||
UPDATE storage.instances SET | ||
instance = instance || _toplevelsimpleprops || | ||
jsonb_strip_nulls( | ||
jsonb_set( | ||
'{"DataValues":""}', | ||
'{DataValues}', | ||
CASE WHEN instance -> 'DataValues' IS NOT NULL THEN | ||
instance -> 'DataValues' || _datavalues | ||
ELSE | ||
_datavalues | ||
END | ||
) | ||
), | ||
lastchanged = _lastchanged | ||
WHERE _alternateid = alternateid | ||
RETURNING instance; | ||
ELSIF _presentationtexts IS NOT NULL THEN | ||
RETURN QUERY | ||
UPDATE storage.instances SET | ||
instance = instance || _toplevelsimpleprops || | ||
jsonb_strip_nulls( | ||
jsonb_set( | ||
'{"PresentationTexts":""}', | ||
'{PresentationTexts}', | ||
CASE WHEN instance -> 'PresentationTexts' IS NOT NULL THEN | ||
instance -> 'PresentationTexts' || _presentationtexts | ||
ELSE | ||
_presentationtexts | ||
END | ||
) | ||
), | ||
lastchanged = _lastchanged | ||
WHERE _alternateid = alternateid | ||
RETURNING instance; | ||
ELSIF _completeconfirmations IS NOT NULL THEN | ||
RETURN QUERY | ||
UPDATE storage.instances SET | ||
instance = instance || _toplevelsimpleprops || | ||
jsonb_set( | ||
'{"CompleteConfirmations":""}', | ||
'{CompleteConfirmations}', | ||
CASE WHEN instance -> 'CompleteConfirmations' IS NOT NULL THEN | ||
instance -> 'CompleteConfirmations' || _completeconfirmations | ||
ELSE | ||
_completeconfirmations | ||
END | ||
), | ||
lastchanged = _lastchanged | ||
WHERE _alternateid = alternateid | ||
RETURNING instance; | ||
ELSIF _status IS NOT NULL AND _process IS NULL THEN | ||
RETURN QUERY | ||
UPDATE storage.instances SET | ||
instance = instance || | ||
jsonb_set( | ||
instance || _toplevelsimpleprops, | ||
'{Status}', | ||
CASE WHEN instance -> 'Status' IS NOT NULL THEN | ||
instance -> 'Status' || _status | ||
ELSE | ||
_status | ||
END | ||
), | ||
lastchanged = _lastchanged | ||
WHERE _alternateid = alternateid | ||
RETURNING instance; | ||
ELSIF _substatus IS NOT NULL THEN | ||
RETURN QUERY | ||
UPDATE storage.instances SET | ||
instance = instance || | ||
jsonb_set( | ||
instance || _toplevelsimpleprops, | ||
'{Status, Substatus}', | ||
jsonb_strip_nulls(_substatus) | ||
), | ||
lastchanged = _lastchanged | ||
WHERE _alternateid = alternateid | ||
RETURNING instance; | ||
ELSIF _process IS NOT NULL AND _status IS NOT NULL THEN | ||
RETURN QUERY | ||
UPDATE storage.instances SET | ||
instance = instance || | ||
jsonb_set( | ||
instance || _toplevelsimpleprops, | ||
'{Process}', | ||
jsonb_strip_nulls(_process) | ||
) || | ||
jsonb_set( | ||
'{"Status":""}', | ||
'{Status}', | ||
CASE WHEN instance -> 'Status' IS NOT NULL THEN | ||
instance -> 'Status' || _status | ||
ELSE | ||
_status | ||
END | ||
), | ||
lastchanged = _lastchanged, | ||
taskid = _taskid | ||
WHERE _alternateid = alternateid | ||
RETURNING instance; | ||
ELSIF _process IS NOT NULL THEN | ||
RETURN QUERY | ||
UPDATE storage.instances SET | ||
instance = instance || | ||
jsonb_set( | ||
instance || _toplevelsimpleprops, | ||
'{Process}', | ||
jsonb_strip_nulls(_process) | ||
), | ||
lastchanged = _lastchanged, | ||
taskid = _taskid | ||
WHERE _alternateid = alternateid | ||
RETURNING instance; | ||
ELSE | ||
RAISE EXCEPTION 'Unexpected parameters to update instance'; | ||
END IF; | ||
END; | ||
$BODY$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.