-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
black black migrations, drop generic foreign keys usage black fixture fix ut, migrations migrations merge fix ut migration merge fix
- Loading branch information
marekbiczysko
committed
Nov 6, 2024
1 parent
3e1b2a7
commit c3f031f
Showing
117 changed files
with
1,655 additions
and
1,459 deletions.
There are no files selected for viewing
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
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
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
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
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
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
62 changes: 62 additions & 0 deletions
62
src/hct_mis_api/apps/grievance/migrations/0074_migration.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,62 @@ | ||
# Generated by Django 3.2.25 on 2024-09-25 17:16 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def migrate_payment_tickets_generic_foreign_key_to_onetoone(apps, schema_editor): | ||
TicketComplaintDetails = apps.get_model("grievance", "TicketComplaintDetails") | ||
TicketSensitiveDetails = apps.get_model("grievance", "TicketSensitiveDetails") | ||
|
||
Payment = apps.get_model("payment", "Payment") | ||
ContentType = apps.get_model("contenttypes", "ContentType") | ||
|
||
ticket_complaint_details_to_update = [] | ||
ticket_sensitive_details_to_update = [] | ||
|
||
for model in [TicketComplaintDetails, TicketSensitiveDetails]: | ||
for ticket_details in model.objects.exclude(payment_content_type__isnull=True, payment_object_id__isnull=True): | ||
if ticket_details.payment_content_type.model == "payment": | ||
related_instance = Payment.objects.get(id=ticket_details.payment_object_id) | ||
ticket_details.payment = related_instance | ||
if model == TicketComplaintDetails: | ||
ticket_complaint_details_to_update.append(ticket_details) | ||
else: | ||
ticket_sensitive_details_to_update.append(ticket_details) | ||
|
||
TicketComplaintDetails.objects.bulk_update(ticket_complaint_details_to_update, ["payment"]) | ||
TicketSensitiveDetails.objects.bulk_update(ticket_sensitive_details_to_update, ["payment"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("grievance", "0073_migration"), | ||
("payment", "0149_migration"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="ticketcomplaintdetails", | ||
name="payment", | ||
field=models.OneToOneField( | ||
to="payment.Payment", | ||
null=True, # Temporarily allow nulls for migration purposes | ||
on_delete=models.CASCADE, | ||
related_name="ticket_complaint_details", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="ticketsensitivedetails", | ||
name="payment", | ||
field=models.OneToOneField( | ||
to="payment.Payment", | ||
null=True, # Temporarily allow nulls for migration purposes | ||
on_delete=models.CASCADE, | ||
related_name="ticket_sensitive_details", | ||
), | ||
), | ||
migrations.RunPython( | ||
migrate_payment_tickets_generic_foreign_key_to_onetoone, | ||
migrations.RunPython.noop, | ||
), | ||
] |
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
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
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
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
Oops, something went wrong.