# Generated by Django 5.2.14 on 2026-07-03 18:45

from django.db import migrations, models


def backfill_price_per_run(apps, schema_editor):
    """Populate price_per_run for variants already priced (price // runs)."""
    BpcVariant = apps.get_model("shop", "BpcVariant")
    updates = []
    for variant in BpcVariant.objects.filter(price__gt=0, runs__gt=0):
        variant.price_per_run = variant.price // variant.runs
        updates.append(variant)
    if updates:
        BpcVariant.objects.bulk_update(updates, ["price_per_run"])


class Migration(migrations.Migration):

    dependencies = [
        ('shop', '0015_bpclisting_bpcvariant_characterblueprint_and_more'),
    ]

    operations = [
        migrations.AddField(
            model_name='bpcvariant',
            name='price_per_run',
            field=models.PositiveBigIntegerField(default=0),
        ),
        migrations.RunPython(
            backfill_price_per_run, migrations.RunPython.noop
        ),
    ]
