# Generated by Django 6.0.6 on 2026-07-12 15:38

from django.db import migrations


def copy_team_to_teams(apps, schema_editor):
    Event = apps.get_model("events", "Event")
    for event in Event.objects.exclude(team__isnull=True).iterator():
        event.teams.add(event.team_id)


def copy_teams_to_team(apps, schema_editor):
    Event = apps.get_model("events", "Event")
    for event in Event.objects.iterator():
        first_team = event.teams.first()
        if first_team is not None:
            event.team = first_team
            event.save(update_fields=["team"])


class Migration(migrations.Migration):

    dependencies = [
        ('events', '0002_add_event_audience'),
    ]

    operations = [
        migrations.RunPython(copy_team_to_teams, copy_teams_to_team),
    ]
