From 1df1c86128d4168272cbd8aefce7d577af52c046 Mon Sep 17 00:00:00 2001 From: Alessio Cialini Date: Mon, 26 Aug 2024 16:32:31 +0200 Subject: [PATCH] [PPANTT-51] feat: introduced python scripts to update data of iban and iban master --- .../updateIbanFkPa/oracleUpdatesIbanFkPa.py | 17 +++++++++++++++++ .../updateIbanFkPa/postgresUpdateIbanFkPa.py | 17 +++++++++++++++++ .../oracleUpdatesIbanMasterDueDate.py | 17 +++++++++++++++++ .../postgresUpdateIbanMasterDueDate.py | 17 +++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 scripts/utils/updateIbanFkPa/oracleUpdatesIbanFkPa.py create mode 100644 scripts/utils/updateIbanFkPa/postgresUpdateIbanFkPa.py create mode 100644 scripts/utils/updateIbanMasterDueDate/oracleUpdatesIbanMasterDueDate.py create mode 100644 scripts/utils/updateIbanMasterDueDate/postgresUpdateIbanMasterDueDate.py diff --git a/scripts/utils/updateIbanFkPa/oracleUpdatesIbanFkPa.py b/scripts/utils/updateIbanFkPa/oracleUpdatesIbanFkPa.py new file mode 100644 index 000000000..7278f1064 --- /dev/null +++ b/scripts/utils/updateIbanFkPa/oracleUpdatesIbanFkPa.py @@ -0,0 +1,17 @@ +import os +import oracledb + +connection = oracledb.connect( + dsn=os.environ['SPRING_DATASOURCE_HOST'], + port=os.environ['SPRING_DATASOURCE_PORT'], + user=os.environ['SPRING_DATASOURCE_USERNAME'], + password=os.environ['SPRING_DATASOURCE_PASSWORD'] +) +cursor = connection.cursor() + +cursor.execute("UPDATE iban SET fk_pa = t.ext_pa FROM (SELECT master.fk_pa as ext_pa, master.fk_iban, MIN(master.inserted_date) FROM iban ib JOIN iban_master master ON master.fk_iban = ib.obj_id GROUP BY master.fk_pa, master.fk_iban) t WHERE obj_id = t.fk_iban AND fk_pa IS NULL") +connection.commit() + +cursor.close() +connection.close() + diff --git a/scripts/utils/updateIbanFkPa/postgresUpdateIbanFkPa.py b/scripts/utils/updateIbanFkPa/postgresUpdateIbanFkPa.py new file mode 100644 index 000000000..5008cc227 --- /dev/null +++ b/scripts/utils/updateIbanFkPa/postgresUpdateIbanFkPa.py @@ -0,0 +1,17 @@ +import os +import psycopg2 + +sql_statement = 'UPDATE iban SET fk_pa = t.ext_pa FROM (SELECT master.fk_pa as ext_pa, master.fk_iban, MIN(master.inserted_date) FROM iban ib JOIN iban_master master ON master.fk_iban = ib.obj_id GROUP BY master.fk_pa, master.fk_iban) t WHERE obj_id = t.fk_iban AND fk_pa IS NULL' +connection = oracledb.connect( + database=os.environ['SPRING_DATASOURCE_DB'] + host=os.environ['SPRING_DATASOURCE_HOST'], + port=os.environ['SPRING_DATASOURCE_PORT'], + user=os.environ['SPRING_DATASOURCE_USERNAME'], + password=os.environ['SPRING_DATASOURCE_PASSWORD'] +) +cursor = connection.cursor() +cursor.execute(sql_statement) +connection.commit() + +cursor.close() +connection.close() diff --git a/scripts/utils/updateIbanMasterDueDate/oracleUpdatesIbanMasterDueDate.py b/scripts/utils/updateIbanMasterDueDate/oracleUpdatesIbanMasterDueDate.py new file mode 100644 index 000000000..ba87f4645 --- /dev/null +++ b/scripts/utils/updateIbanMasterDueDate/oracleUpdatesIbanMasterDueDate.py @@ -0,0 +1,17 @@ +import os +import oracledb + +connection = oracledb.connect( + dsn=os.environ['SPRING_DATASOURCE_HOST'], + port=os.environ['SPRING_DATASOURCE_PORT'], + user=os.environ['SPRING_DATASOURCE_USERNAME'], + password=os.environ['SPRING_DATASOURCE_PASSWORD'] +) +cursor = connection.cursor() + +cursor.execute("UPDATE iban_master SET due_date = t.due_date FROM (SELECT DISTINCT ib.obj_id, ib.due_date FROM iban ib JOIN iban_master master ON master.fk_iban = ib.obj_id WHERE master.due_date IS NULL) t WHERE fk_iban = t.obj_id") +connection.commit() + +cursor.close() +connection.close() + diff --git a/scripts/utils/updateIbanMasterDueDate/postgresUpdateIbanMasterDueDate.py b/scripts/utils/updateIbanMasterDueDate/postgresUpdateIbanMasterDueDate.py new file mode 100644 index 000000000..73337df9d --- /dev/null +++ b/scripts/utils/updateIbanMasterDueDate/postgresUpdateIbanMasterDueDate.py @@ -0,0 +1,17 @@ +import os +import psycopg2 + +sql_statement = '"UPDATE iban_master SET due_date = t.due_date FROM (SELECT DISTINCT ib.obj_id, ib.due_date FROM iban ib JOIN iban_master master ON master.fk_iban = ib.obj_id WHERE master.due_date IS NULL) t WHERE fk_iban = t.obj_id"' +connection = oracledb.connect( + database=os.environ['SPRING_DATASOURCE_DB'] + host=os.environ['SPRING_DATASOURCE_HOST'], + port=os.environ['SPRING_DATASOURCE_PORT'], + user=os.environ['SPRING_DATASOURCE_USERNAME'], + password=os.environ['SPRING_DATASOURCE_PASSWORD'] +) +cursor = connection.cursor() +cursor.execute(sql_statement) +connection.commit() + +cursor.close() +connection.close()