From 7b8dfddbc2e60c27976383fcacdbd89c77933cea Mon Sep 17 00:00:00 2001 From: Hamed Valiollahi Bayeki Date: Fri, 12 Jan 2024 13:36:14 -0800 Subject: [PATCH 1/2] fix: correct effective date of transfer 2095 --- ...correct_effective_date_of_transfer_2095.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py diff --git a/backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py b/backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py new file mode 100644 index 000000000..41e683d85 --- /dev/null +++ b/backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py @@ -0,0 +1,39 @@ +import logging +from django.db import migrations, transaction +from django.utils import timezone + +def update_transfer_effective_date(apps, schema_editor): + """ + Update transfer ID #2095 to correct effective date from March 30, 2022 to March 30, 2023. + If any record is not updated, all changes are reverted. + """ + credit_trade_history = apps.get_model('api', 'CreditTradeHistory') + new_trade_effective_date = timezone.datetime.strptime('2023-03-30', "%Y-%m-%d").date() + + # IDs of the CreditTradeHistory records to update + history_ids = [4666, 4709] + + with transaction.atomic(): + for history_id in history_ids: + try: + history = credit_trade_history.objects.get(id=history_id) + history.trade_effective_date = new_trade_effective_date + history.save() + except credit_trade_history.DoesNotExist: + logging.warning( + 'Failed to update CreditTradeHistory: No entry found with id "%s"; ' + 'all changes within this transaction will be reverted.', + history_id + ) + +class Migration(migrations.Migration): + """ + Attaches the update function to the migration operations + """ + dependencies = [ + ('api', '0019_update_signing_authority_declaration_statement'), + ] + + operations = [ + migrations.RunPython(update_transfer_effective_date), + ] From 0708d03dfe1e35823e27396d64cd4631790c4bbc Mon Sep 17 00:00:00 2001 From: Hamed Valiollahi Bayeki Date: Mon, 15 Jan 2024 12:57:26 -0800 Subject: [PATCH 2/2] fix: add a reverse noop to avoid downgrade issues --- .../migrations/0020_correct_effective_date_of_transfer_2095.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py b/backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py index 41e683d85..fbb0d2b99 100644 --- a/backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py +++ b/backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py @@ -35,5 +35,5 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython(update_transfer_effective_date), + migrations.RunPython(update_transfer_effective_date, reverse_code=migrations.RunPython.noop), ]