From f4152541b1839ca60bfe11af2a59624daa13046a Mon Sep 17 00:00:00 2001 From: Irakli Merabishvili Date: Mon, 8 Apr 2024 18:32:00 +0400 Subject: [PATCH] [MODFIN-358] - Add tenantId to the locations schema for restrict by Fund functionality --- ramls/acq-models | 2 +- .../templates/db_scripts/budget_encumbrances_rollover.sql | 2 +- .../db_scripts/migration/transform_location_ids_array.sql | 8 ++++++++ src/main/resources/templates/db_scripts/schema.json | 5 +++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/templates/db_scripts/migration/transform_location_ids_array.sql diff --git a/ramls/acq-models b/ramls/acq-models index 264917d8..51bf89a7 160000 --- a/ramls/acq-models +++ b/ramls/acq-models @@ -1 +1 @@ -Subproject commit 264917d88c6847a54c588102ab5b58ea933f02cc +Subproject commit 51bf89a771c391ef4da4abf076bcd39e0a756ea5 diff --git a/src/main/resources/templates/db_scripts/budget_encumbrances_rollover.sql b/src/main/resources/templates/db_scripts/budget_encumbrances_rollover.sql index 7fcd1b13..118eaf57 100644 --- a/src/main/resources/templates/db_scripts/budget_encumbrances_rollover.sql +++ b/src/main/resources/templates/db_scripts/budget_encumbrances_rollover.sql @@ -542,7 +542,7 @@ CREATE OR REPLACE FUNCTION ${myuniversity}_${mymodule}.budget_encumbrances_rollo 'fundTypeName', fund_type->'name', 'acqUnitIds', fund->'acqUnitIds', 'donorOrganizationIds', fund->'donorOrganizationIds', - 'locationIds', fund->'locationIds', + 'locations', fund->'locations', 'allocatedFromIds', fund->'allocatedFromIds', 'allocatedFromNames', allocatedFromNames, 'allocatedToIds', fund->'allocatedToIds', diff --git a/src/main/resources/templates/db_scripts/migration/transform_location_ids_array.sql b/src/main/resources/templates/db_scripts/migration/transform_location_ids_array.sql new file mode 100644 index 00000000..ff24bb1b --- /dev/null +++ b/src/main/resources/templates/db_scripts/migration/transform_location_ids_array.sql @@ -0,0 +1,8 @@ +-- Transform locationIds arrays to array of objects with locationId field inside them +UPDATE ${myuniversity}_${mymodule}.fund +SET jsonb = jsonb - 'locationIds' || jsonb_build_object( + 'locations', + CASE WHEN jsonb->>'locationIds' = '[]' THEN '[]' ELSE + (SELECT jsonb_agg(jsonb_build_object('locationId', value)) from jsonb_array_elements(jsonb->'locationIds')) END + ) +WHERE jsonb ? 'locationIds'; diff --git a/src/main/resources/templates/db_scripts/schema.json b/src/main/resources/templates/db_scripts/schema.json index be910213..6dfd44b8 100644 --- a/src/main/resources/templates/db_scripts/schema.json +++ b/src/main/resources/templates/db_scripts/schema.json @@ -90,6 +90,11 @@ "run": "after", "snippetPath": "migration/update_budget_rollover.sql", "fromModuleVersion": "mod-finance-storage-8.4.0" + }, + { + "run": "after", + "snippetPath": "migration/transform_location_ids_array.sql", + "fromModuleVersion": "mod-finance-storage-8.7.0" } ], "tables": [