# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-01 23:43
from __future__ import unicode_literals

from django.db import migrations


def create_profiles(apps, schema_editor):
    # We can't import the Person model directly as it may be a newer
    # version than this migration expects. We use the historical version.
    User = apps.get_model("auth", "User")
    Profile = apps.get_model("core", "Profile")
    Game = apps.get_model("core", "Game")
    Team = apps.get_model("core", "Team")

    if Game.objects.all().count() == 0:
        Game.objects.create(state="g1")
    game = Game.objects.all()[0]

    if Team.objects.all().count() == 0:
        Team.objects.create(game=game)
    team = Team.objects.all()[0]

    for instance in User.objects.all():
        profile = Profile.objects.create(user=instance, state="g1")
        profile.groups.create(user=instance, team=team)


def do_nothing(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('auth', '0008_alter_user_username_max_length'),
        ('core', '0008_auto_20170301_2343'),
    ]

    operations = [
        migrations.RunPython(create_profiles, do_nothing),

    ]
