# Generated by Django 2.2.7 on 2019-11-10 16:22
import random
from itertools import islice

from django.db import migrations


def forward_function(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    Employee = apps.get_model("employees", "Employee")
    Branch = apps.get_model("branches", "Branch")
    employees = (
        Employee(
            first_name="mock_f_Employee_{}".format(i),
            last_name="mock_l_Employee_{}".format(i),
            position_title="mock_SDE_{}".format(i % 9 + 1),
            branch=Branch.objects.objects.using(db_alias).filter(
                name__startswith="mock_",
                name__endswith="{}".format(random.randint(1, 10)),
            ),
        )
        for i in range(10000)
    )
    batch_size = 100
    while True:
        batch = list(islice(employees, batch_size))
        if not batch:
            break
        Employee.objects.using(db_alias).bulk_create(batch, batch_size)


def reverse_function(apps, schema_editor):
    db_alias = schema_editor.connection.alias
    Employee = apps.get_model("employees", "Employee")
    Employee.objects.using(db_alias).filter(first_name__startswith="mock_f_").delete()


class Migration(migrations.Migration):

    dependencies = [
        ("employees", "0001_initial"),
        ("branches", "0004_auto_20191110_1922"),
    ]

    operations = [migrations.RunPython(forward_function, reverse_function)]
