From de7d274c381d691555f4af373e64c7f329f9faae Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 16 Dec 2024 08:58:50 +0000 Subject: [PATCH 1/4] 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; From 73e25e58de44c0e74431219d64af3bc27d79fb55 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 16 Dec 2024 08:58:50 +0000 Subject: [PATCH 2/4] PAGOPA-2483 DB debtor fields: fix --- 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 | 60 +++++++++++++++++++ 11 files changed, 71 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..d39ceed0 --- /dev/null +++ b/src/main/resources/db/migration/V022__ALTER_PO_DEBTOR_FIELDS.sql @@ -0,0 +1,60 @@ +-- 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 DEFAULT 'F', +ALTER COLUMN "type" SET NOT NULL; From dac825f14ea0609d28f82bbdc7fdb2589de8639a Mon Sep 17 00:00:00 2001 From: aacitelli Date: Thu, 19 Dec 2024 11:56:53 +0100 Subject: [PATCH 3/4] [PAGOPA-2483] v3 DB debtor fields: only new fields without past data --- .../V023__ALTER_PO_DEBTOR_FIELDS.sql | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql b/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql index 00db8f1e..603377ed 100644 --- a/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql +++ b/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql @@ -1,4 +1,34 @@ --- Step 1: Added columns without default to avoid FULL TABLE SCAN +-- Adding new columns with DEFAULT and NOT NULL constraints in a single ALTER TABLE statement: +-- a. Performance: PostgreSQL optimizes the operation by virtually applying a DEFAULT value to existing rows without physically writing to them, reducing I/O overhead. +-- b. Better for Large Tables: minimizes the risk of performance degradation: PostgreSQL treats the +-- DEFAULT value as a "virtual" value for rows where the column has not been explicitly set. +-- This significantly reduces the amount of time and resources required to add the column, +-- making it more suitable for high-traffic environments or large-scale datasets. + +ALTER TABLE payment_option + ADD COLUMN IF NOT EXISTS fiscal_code VARCHAR(255) DEFAULT 'NA' NOT NULL, + ADD COLUMN IF NOT EXISTS full_name VARCHAR(255) DEFAULT 'NA' NOT NULL, + ADD COLUMN IF NOT EXISTS "type" VARCHAR(255) DEFAULT 'F' NOT NULL, + 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); + +/* + +-- The decision was made not to adopt the script version that used a stored procedure +-- to populate the new columns of the 'payment_option' table based on data from the +-- 'payment_position' table. This choice was made because, during a transitional period, +-- the old APIs will still be used to create debtor positions, leading to data inconsistencies +-- between 'payment_position' and 'payment_option'. + + +-- Step 1: Added columns ALTER TABLE payment_option ADD COLUMN IF NOT exists fiscal_code VARCHAR(255), ADD COLUMN IF NOT EXISTS full_name VARCHAR(255), @@ -69,9 +99,9 @@ AS END LOOP; ALTER TABLE payment_option ALTER COLUMN fiscal_code SET NOT NULL, - ALTER COLUMN fiscal_code SET DEFAULT 'ANONIMO', + ALTER COLUMN fiscal_code SET DEFAULT 'NA', ALTER COLUMN full_name SET NOT NULL, - ALTER COLUMN full_name SET DEFAULT 'ANONIMO', + ALTER COLUMN full_name SET DEFAULT 'NA', ALTER COLUMN "type" SET DEFAULT 'F', ALTER COLUMN "type" SET NOT NULL; RAISE NOTICE 'Total rows updated: %', total_rows_updated; @@ -79,4 +109,5 @@ AS CALL update_payment_option_batch(10000); - DROP PROCEDURE IF EXISTS update_payment_option_batch; \ No newline at end of file + DROP PROCEDURE IF EXISTS update_payment_option_batch; + */ \ No newline at end of file From 4d0f116e3e928fef4dda6ded13f4d872b8508efe Mon Sep 17 00:00:00 2001 From: aacitelli Date: Thu, 19 Dec 2024 11:56:53 +0100 Subject: [PATCH 4/4] [PAGOPA-2483] v3 DB debtor fields: added missing script --- .../V022__UPDATE_PP_SERVICE_TYPE.sql | 31 +++++++++++++++ .../V023__ALTER_PO_DEBTOR_FIELDS.sql | 39 +++++++++++++++++-- 2 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/db/migration/V022__UPDATE_PP_SERVICE_TYPE.sql diff --git a/src/main/resources/db/migration/V022__UPDATE_PP_SERVICE_TYPE.sql b/src/main/resources/db/migration/V022__UPDATE_PP_SERVICE_TYPE.sql new file mode 100644 index 00000000..0165b1a7 --- /dev/null +++ b/src/main/resources/db/migration/V022__UPDATE_PP_SERVICE_TYPE.sql @@ -0,0 +1,31 @@ +-- Primo step: aggiornamento per 'WISP' +DO $$ +BEGIN + -- Aggiornamento per 'WISP' + UPDATE payment_position + SET service_type = 'WISP' + WHERE iupd ILIKE 'wisp_%'; + +EXCEPTION + WHEN OTHERS THEN + -- Gestione dell'errore + RAISE NOTICE 'Errore durante l''aggiornamento per WISP. Tipo di errore: %, Messaggio di errore: %', SQLSTATE, SQLERRM; + RAISE; +END; +$$; + +-- Secondo step: aggiornamento per 'ACA' +DO $$ +BEGIN + -- Aggiornamento per 'ACA' + UPDATE payment_position + SET service_type = 'ACA' + WHERE iupd ILIKE 'aca_%'; + +EXCEPTION + WHEN OTHERS THEN + -- Gestione dell'errore + RAISE NOTICE 'Errore durante l''aggiornamento per ACA. Tipo di errore: %, Messaggio di errore: %', SQLSTATE, SQLERRM; + RAISE; +END; +$$; \ No newline at end of file diff --git a/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql b/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql index 00db8f1e..603377ed 100644 --- a/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql +++ b/src/main/resources/db/migration/V023__ALTER_PO_DEBTOR_FIELDS.sql @@ -1,4 +1,34 @@ --- Step 1: Added columns without default to avoid FULL TABLE SCAN +-- Adding new columns with DEFAULT and NOT NULL constraints in a single ALTER TABLE statement: +-- a. Performance: PostgreSQL optimizes the operation by virtually applying a DEFAULT value to existing rows without physically writing to them, reducing I/O overhead. +-- b. Better for Large Tables: minimizes the risk of performance degradation: PostgreSQL treats the +-- DEFAULT value as a "virtual" value for rows where the column has not been explicitly set. +-- This significantly reduces the amount of time and resources required to add the column, +-- making it more suitable for high-traffic environments or large-scale datasets. + +ALTER TABLE payment_option + ADD COLUMN IF NOT EXISTS fiscal_code VARCHAR(255) DEFAULT 'NA' NOT NULL, + ADD COLUMN IF NOT EXISTS full_name VARCHAR(255) DEFAULT 'NA' NOT NULL, + ADD COLUMN IF NOT EXISTS "type" VARCHAR(255) DEFAULT 'F' NOT NULL, + 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); + +/* + +-- The decision was made not to adopt the script version that used a stored procedure +-- to populate the new columns of the 'payment_option' table based on data from the +-- 'payment_position' table. This choice was made because, during a transitional period, +-- the old APIs will still be used to create debtor positions, leading to data inconsistencies +-- between 'payment_position' and 'payment_option'. + + +-- Step 1: Added columns ALTER TABLE payment_option ADD COLUMN IF NOT exists fiscal_code VARCHAR(255), ADD COLUMN IF NOT EXISTS full_name VARCHAR(255), @@ -69,9 +99,9 @@ AS END LOOP; ALTER TABLE payment_option ALTER COLUMN fiscal_code SET NOT NULL, - ALTER COLUMN fiscal_code SET DEFAULT 'ANONIMO', + ALTER COLUMN fiscal_code SET DEFAULT 'NA', ALTER COLUMN full_name SET NOT NULL, - ALTER COLUMN full_name SET DEFAULT 'ANONIMO', + ALTER COLUMN full_name SET DEFAULT 'NA', ALTER COLUMN "type" SET DEFAULT 'F', ALTER COLUMN "type" SET NOT NULL; RAISE NOTICE 'Total rows updated: %', total_rows_updated; @@ -79,4 +109,5 @@ AS CALL update_payment_option_batch(10000); - DROP PROCEDURE IF EXISTS update_payment_option_batch; \ No newline at end of file + DROP PROCEDURE IF EXISTS update_payment_option_batch; + */ \ No newline at end of file