# Generated by Django 4.0.4 on 2022-04-27 18:30

from django.db import migrations, models


def forwards(apps, schema_editor):
    BasketItem = apps.get_model("purchase", "BasketItem")
    items = (
        BasketItem.objects.using(schema_editor.connection.alias)
        .all()
        .select_related("product")
    )
    for item in items:
        item.unit_price_cents = item.product.unit_price_cents
    BasketItem.objects.bulk_update(items, ["unit_price_cents"])


class Migration(migrations.Migration):
    dependencies = [
        ("purchase", "0005_alter_basket_options_alter_basketitem_options_and_more"),
    ]

    operations = [
        migrations.AddField(
            model_name="basketitem",
            name="unit_price_cents",
            field=models.PositiveIntegerField(
                help_text="product's unit price in cents at the time of purchase",
                null=True,
                verbose_name="unit price (cents)",
            ),
        ),
        migrations.RunPython(forwards, migrations.RunPython.noop),
    ]
