-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: PagoPA-2483 V3 DB debtor fields 2️⃣ ㏈ #278
Open
alessio-acitelli
wants to merge
19
commits into
main
Choose a base branch
from
PAGOPA-2483-v3-DB-debtor-fields
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−0
Open
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
de7d274
PAGOPA-2483 DB debtor fields: create new fields and enhance them
pagopa-github-bot 73e25e5
PAGOPA-2483 DB debtor fields: fix
pagopa-github-bot 78ed383
Merge branch 'PAGOPA-2483-v3-DB-debtor-fields' of
80d9750
Merge branch 'main' into PAGOPA-2483-v3-DB-debtor-fields
alessio-acitelli 41b5649
[PAGOPA-2483] v3 DB debtor fields: procedure for standalone transaction
777f950
Merge branch 'PAGOPA-2483-v3-DB-debtor-fields' of
88e3942
Merge branch 'PAGOPA-2483-v3-DB-debtor-fields' of
57bc1f1
Merge branch 'PAGOPA-2483-v3-DB-debtor-fields' of
32e9916
[PAGOPA-2483] v3 DB debtor fields: update to version 23
132d892
Merge branch 'PAGOPA-2483-v3-DB-debtor-fields' of
c1457b8
[PAGOPA-2483] v3 DB debtor fields: added default value
942916e
Merge branch 'PAGOPA-2483-v3-DB-debtor-fields' of https://github.com/…
dd66962
Merge branch 'main' into PAGOPA-2483-v3-DB-debtor-fields
alessio-acitelli dac825f
[PAGOPA-2483] v3 DB debtor fields: only new fields without past data
4d0f116
[PAGOPA-2483] v3 DB debtor fields: added missing script
a53c9eb
Merge branch 'PAGOPA-2483-v3-DB-debtor-fields' of https://github.com/…
e7f8914
Merge branch 'main' into PAGOPA-2483-v3-DB-debtor-fields
alessio-acitelli 83965b6
Merge branch 'main' into PAGOPA-2483-v3-DB-debtor-fields
cap-ang c868ccb
Merge branch 'main' into PAGOPA-2483-v3-DB-debtor-fields
cap-ang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/main/resources/db/migration/V022__ALTER_PO_DEBTOR_FIELDS.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,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", | ||
cap-ang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cycle is all in one transaction, what is the acquired lock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it's a single transaction so the lock on the table is held until the end (even if I do updates by block size). I correct.