From d1e22257529f0aaf34bf06e141717e2331e89bbf Mon Sep 17 00:00:00 2001 From: Machiko Yasuda Date: Mon, 30 Sep 2024 23:27:12 +0000 Subject: [PATCH] refactor(db): combine migration into 1 and add migrate_data() --- ...transitagency_enrollment_flows_and_more.py} | 9 ++++++--- .../0029_alter_enrollmentflow_label.py | 18 ------------------ benefits/core/models.py | 2 +- 3 files changed, 7 insertions(+), 22 deletions(-) rename benefits/core/migrations/{0028_refactor_transitagency_enrollmentflow_relationship.py => 0028_remove_transitagency_enrollment_flows_and_more.py} (77%) delete mode 100644 benefits/core/migrations/0029_alter_enrollmentflow_label.py diff --git a/benefits/core/migrations/0028_refactor_transitagency_enrollmentflow_relationship.py b/benefits/core/migrations/0028_remove_transitagency_enrollment_flows_and_more.py similarity index 77% rename from benefits/core/migrations/0028_refactor_transitagency_enrollmentflow_relationship.py rename to benefits/core/migrations/0028_remove_transitagency_enrollment_flows_and_more.py index 680b18baf..5f1f61a1f 100644 --- a/benefits/core/migrations/0028_refactor_transitagency_enrollmentflow_relationship.py +++ b/benefits/core/migrations/0028_remove_transitagency_enrollment_flows_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.1 on 2024-09-25 16:47 +# Generated by Django 5.1 on 2024-09-30 23:25 import django.db.models.deletion from django.db import migrations, models @@ -6,7 +6,6 @@ def migrate_data(apps, schema_editor): TransitAgency = apps.get_model("core", "TransitAgency") - for agency in TransitAgency.objects.all(): for flow in agency.enrollment_flows.all(): flow.transit_agency = agency @@ -26,11 +25,15 @@ class Migration(migrations.Migration): field=models.ForeignKey( blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to="core.transitagency" ), - preserve_default=False, ), migrations.RunPython(migrate_data), migrations.RemoveField( model_name="transitagency", name="enrollment_flows", ), + migrations.AlterField( + model_name="enrollmentflow", + name="label", + field=models.TextField(help_text="A human readable label, used as the display text in Admin.", null=True), + ), ] diff --git a/benefits/core/migrations/0029_alter_enrollmentflow_label.py b/benefits/core/migrations/0029_alter_enrollmentflow_label.py deleted file mode 100644 index c31b80288..000000000 --- a/benefits/core/migrations/0029_alter_enrollmentflow_label.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 5.1 on 2024-09-30 06:09 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("core", "0028_refactor_transitagency_enrollmentflow_relationship"), - ] - - operations = [ - migrations.AlterField( - model_name="enrollmentflow", - name="label", - field=models.TextField(help_text="A human readable label, used as the display text in Admin.", null=True), - ), - ] diff --git a/benefits/core/models.py b/benefits/core/models.py index c2cf07a07..7b29a55f0 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -381,7 +381,7 @@ class EnrollmentFlow(models.Model): default=[EnrollmentMethods.DIGITAL, EnrollmentMethods.IN_PERSON], help_text="If the flow is supported by digital enrollment, in-person enrollment, or both", ) - transit_agency = models.ForeignKey(TransitAgency, on_delete=models.PROTECT) + transit_agency = models.ForeignKey(TransitAgency, on_delete=models.PROTECT, null=True, blank=True) class Meta: ordering = ["display_order"]