Skip to content

Commit

Permalink
refactor(db): combine migration into 1 and add migrate_data()
Browse files Browse the repository at this point in the history
  • Loading branch information
machikoyasuda committed Oct 1, 2024
1 parent 38f2a75 commit 890cd55
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# 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


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
Expand All @@ -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),
),
]
18 changes: 0 additions & 18 deletions benefits/core/migrations/0029_alter_enrollmentflow_label.py

This file was deleted.

2 changes: 1 addition & 1 deletion benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 890cd55

Please sign in to comment.