From 33cf0d1975da8f65c0d08ecd67a4fcc776c3c994 Mon Sep 17 00:00:00 2001 From: imerabishvili <144257054+imerabishvili@users.noreply.github.com> Date: Thu, 11 Apr 2024 17:07:39 +0400 Subject: [PATCH] [MODFIN-358] - Add tenantId to the locations schema for restrict by Fund functionality (#406) [MODFIN-358] - Add tenantId to the locations schema for restrict by Fund functionality --- descriptors/ModuleDescriptor-template.json | 2 +- 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 +++++ 5 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/templates/db_scripts/migration/transform_location_ids_array.sql diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 48ba2e7f..10854bf5 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -164,7 +164,7 @@ }, { "id": "finance-storage.funds", - "version": "4.0", + "version": "5.0", "handlers": [ { "methods": ["GET"], 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": [