# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-04-29 11:53
from __future__ import unicode_literals

from django.db import migrations


def _fill_team_owneruser_from_owner(apps, schema_editor):
    Team = apps.get_model('multidb_account', 'Team')
    db_alias = schema_editor.connection.alias
    for team in Team.objects.using(db_alias).all():
        team.owner_user = team.owner.user
        team.save(update_fields=['owner_user'])


def _fill_team_owner_from_owneruser(apps, schema_editor):
    Team = apps.get_model('multidb_account', 'Team')
    db_alias = schema_editor.connection.alias
    for team in Team.objects.using(db_alias).all():
        if team.owner_user and not team.owner:
            team.owner = team.owner_user
            team.save(update_fields=['owner'])


class Migration(migrations.Migration):
    dependencies = [
        ('multidb_account', '0045_add_team_owner_user'),
    ]

    operations = [
        migrations.RunPython(_fill_team_owneruser_from_owner, _fill_team_owner_from_owneruser),
    ]
