-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct effective date of transfer 2095
- Loading branch information
1 parent
2c796da
commit 7b8dfdd
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
backend/api/migrations/0020_correct_effective_date_of_transfer_2095.py
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,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), | ||
] |