# Generated by Django 5.1.4 on 2025-01-14 11:02
#
# The 2024 export had no display label. Support kept reading raw keys off the
# reporting screen, so we derived one for every row that was already imported.

from django.db import migrations


def backfill_labels(apps, schema_editor):
    entry_model = apps.get_model("adjustments", "PromotionCatalogEntry")
    alias = schema_editor.connection.alias
    for entry in entry_model.objects.using(alias).all().order_by("pk"):
        entry.label = f"{entry.campaign_key} tier {entry.tier_key}"
        entry.save(using=alias, update_fields=["label"])


class Migration(migrations.Migration):

    dependencies = [
        ("adjustments", "0003_import_promotion_catalog"),
    ]

    operations = [
        migrations.RunPython(backfill_labels, migrations.RunPython.noop),
    ]
