# Generated by Django 3.1.1 on 2020-09-16 08:08

from django.db import migrations, models
import django.db.models.deletion


def forward_eleven_number_data(apps, schema_editor):
    """Create first eleven number table data."""
    Player = apps.get_model("django_cricket_statistics", "Player")
    FirstElevenNumber = apps.get_model("django_cricket_statistics", "FirstElevenNumber")
    db_alias = schema_editor.connection.alias

    FirstElevenNumber.objects.using(db_alias).bulk_create(
        [
            FirstElevenNumber(pk=player.first_XI_number)
            for player in Player.objects.using(db_alias).exclude(
                first_XI_number__isnull=True
            )
        ]
    )


class Migration(migrations.Migration):

    dependencies = [("django_cricket_statistics", "0003_auto_20200916_0306")]

    operations = [
        migrations.CreateModel(
            name="FirstElevenNumber",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("modified_at", models.DateTimeField(auto_now=True)),
            ],
            options={"abstract": False},
        ),
        migrations.RunPython(forward_eleven_number_data, migrations.RunPython.noop),
    ]
