|
| 1 | +# Generated manually to migrate description fields from subclasses to parent Distribution class |
| 2 | + |
| 3 | +from django.db import migrations |
| 4 | + |
| 5 | + |
| 6 | +def migrate_description_data_forward(apps, schema_editor): |
| 7 | + Distribution = apps.get_model("core", "Distribution") |
| 8 | + ContainerDistribution = apps.get_model("container", "ContainerDistribution") |
| 9 | + ContainerPullThroughDistribution = apps.get_model( |
| 10 | + "container", "ContainerPullThroughDistribution" |
| 11 | + ) |
| 12 | + |
| 13 | + for Model in (ContainerDistribution, ContainerPullThroughDistribution): |
| 14 | + for dist in Model.objects.all(): |
| 15 | + if dist.description: |
| 16 | + parent = Distribution.objects.get(pk=dist.pk) |
| 17 | + if not parent.description: |
| 18 | + parent.description = dist.description |
| 19 | + parent.save(update_fields=["description"]) |
| 20 | + |
| 21 | + |
| 22 | +class Migration(migrations.Migration): |
| 23 | + |
| 24 | + dependencies = [ |
| 25 | + # Ensure parent field exists before copying data |
| 26 | + ("core", "0146_distribution_description"), |
| 27 | + ("container", "0047_containernamespace_pulp_labels"), |
| 28 | + ] |
| 29 | + |
| 30 | + operations = [ |
| 31 | + # Copy description data from subclass tables to parent Distribution table |
| 32 | + migrations.RunPython(migrate_description_data_forward, migrations.RunPython.noop), |
| 33 | + # Remove duplicate fields from subclasses |
| 34 | + migrations.RemoveField(model_name="containerdistribution", name="description"), |
| 35 | + migrations.RemoveField(model_name="containerpullthroughdistribution", name="description"), |
| 36 | + ] |
0 commit comments