# Generated by Django 4.0.8 on 2026-03-31 11:10

from django.db import migrations

def data_campaign(apps, schema_editor):
    Banner = apps.get_model('annoy', 'Banner')
    Campaign = apps.get_model('annoy', 'Campaign')
    for b in Banner.objects.exclude(target=None):
        if b.campaign is None:
            b.campaign = Campaign.objects.create(name='auto')
            b.save()
        c = b.campaign
        c.target = b.target
        c.progress = b.progress
        c.start = b.since
        c.end = b.until
        c.save()


def data_campaign_rev(apps, schema_editor):
    Banner = apps.get_model('annoy', 'Banner')
    Campaign = apps.get_model('annoy', 'Campaign')
    for c in Campaign.objects.exclude(target=None):
        for b in c.banner_set.all():
            b.target = c.target
            b.progress = c.progress
            b.save()


class Migration(migrations.Migration):

    dependencies = [
        ('annoy', '0020_campaign_end_campaign_landing_campaign_priority_and_more'),
    ]

    operations = [
        migrations.RunPython(
            data_campaign,
            data_campaign_rev
        )
    ]
