From de7d274c381d691555f4af373e64c7f329f9faae Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 16 Dec 2024 08:58:50 +0000 Subject: [PATCH] PAGOPA-2483 DB debtor fields: create new fields and enhance them --- helm/Chart.yaml | 4 +- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_internal_massive.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- .../V022__ALTER_PO_DEBTOR_FIELDS.sql | 59 +++++++++++++++++++ 11 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 src/main/resources/db/migration/V022__ALTER_PO_DEBTOR_FIELDS.sql diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 9b51f352..98141cd6 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.176.0 -appVersion: 0.11.62-4-PAGOPA-2459-Expired-update +version: 0.177.0 +appVersion: 0.11.63 dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index a28e94ff..36dc89d3 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.62-4-PAGOPA-2459-Expired-update" + tag: "0.11.63" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index b3fc3452..73c02e98 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.62-4-PAGOPA-2459-Expired-update" + tag: "0.11.63" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 286c0726..e8a93d58 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.62-4-PAGOPA-2459-Expired-update" + tag: "0.11.63" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index 4a5f70e6..46dbb8e4 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.62-4-PAGOPA-2459-Expired-update" + "version": "0.11.63" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index a0bd53b5..6c217abc 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.62-4-PAGOPA-2459-Expired-update" + "version": "0.11.63" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index d2106539..485024df 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.62-4-PAGOPA-2459-Expired-update" + "version": "0.11.63" }, "servers": [ { diff --git a/openapi/openapi_internal_massive.json b/openapi/openapi_internal_massive.json index 81e26801..c59cef07 100644 --- a/openapi/openapi_internal_massive.json +++ b/openapi/openapi_internal_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.62-4-PAGOPA-2459-Expired-update" + "version": "0.11.63" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index 958b4110..0b2b408b 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.62-4-PAGOPA-2459-Expired-update" + "version": "0.11.63" }, "servers": [ { diff --git a/pom.xml b/pom.xml index bb5a7bcc..84447d77 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.62-4-PAGOPA-2459-Expired-update + 0.11.63 Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie diff --git a/src/main/resources/db/migration/V022__ALTER_PO_DEBTOR_FIELDS.sql b/src/main/resources/db/migration/V022__ALTER_PO_DEBTOR_FIELDS.sql new file mode 100644 index 00000000..271b26cf --- /dev/null +++ b/src/main/resources/db/migration/V022__ALTER_PO_DEBTOR_FIELDS.sql @@ -0,0 +1,59 @@ +-- Step 1: Added columns without default to avoid FULL TABLE SCAN +ALTER TABLE payment_option +ADD COLUMN IF NOT EXISTS fiscal_code varchar(255), +ADD COLUMN IF NOT EXISTS full_name varchar(255), +ADD COLUMN IF NOT EXISTS "type" varchar(255), +ADD COLUMN IF NOT EXISTS street_name varchar(255), +ADD COLUMN IF NOT EXISTS civic_number varchar(255), +ADD COLUMN IF NOT EXISTS postal_code varchar(255), +ADD COLUMN IF NOT EXISTS city varchar(255), +ADD COLUMN IF NOT EXISTS province varchar(255), +ADD COLUMN IF NOT EXISTS region varchar(255), +ADD COLUMN IF NOT EXISTS country varchar(255), +ADD COLUMN IF NOT EXISTS email varchar(255), +ADD COLUMN IF NOT EXISTS phone varchar(255); + +-- Step 2: Batch update to minimize lock +DO $$ +DECLARE + batch_size INT := 10000; -- Batch size + rows_updated INT; +BEGIN + LOOP + WITH rows_to_update AS ( + SELECT po.payment_position_id, pp.fiscal_code, pp.full_name, pp."type", + pp.street_name, pp.civic_number, pp.postal_code, pp.city, + pp.province, pp.region, pp.country, pp.email, pp.phone + FROM payment_option AS po + JOIN payment_position AS pp + ON po.payment_position_id = pp.id + WHERE po.fiscal_code IS NULL -- To update only the rows not yet processed + LIMIT batch_size + ) + UPDATE payment_option AS po + SET fiscal_code = rows_to_update.fiscal_code, + full_name = rows_to_update.full_name, + "type" = rows_to_update."type", + street_name = rows_to_update.street_name, + civic_number = rows_to_update.civic_number, + postal_code = rows_to_update.postal_code, + city = rows_to_update.city, + province = rows_to_update.province, + region = rows_to_update.region, + country = rows_to_update.country, + email = rows_to_update.email, + phone = rows_to_update.phone + FROM rows_to_update + WHERE po.payment_position_id = rows_to_update.payment_position_id; + + GET DIAGNOSTICS rows_updated = ROW_COUNT; + + EXIT WHEN rows_updated = 0; + END LOOP; +END $$; + +-- Step 3: Set the columns that must always be filled to NOT NULL +ALTER TABLE payment_option +ALTER COLUMN fiscal_code SET NOT NULL, +ALTER COLUMN full_name SET NOT NULL, +ALTER COLUMN "type" SET NOT NULL;