# Generated by Django 2.0.2 on 2018-08-24 13:39

from django.db import migrations


def match_eth_address_to_user(apps, schema_editor):
    Company = apps.get_model('company', 'Company')
    User = apps.get_model('bdn_auth', 'User')
    for company in Company.objects.all():
        if not company.eth_address:
            continue
        eth_address = company.eth_address.strip()
        user = User.objects\
            .filter(username__iexact=eth_address)\
            .first()
        if user:
            company.user = user
            company.save()


class Migration(migrations.Migration):

    dependencies = [
        ('company', '0002_company_user'),
    ]

    operations = [
        migrations.RunPython(match_eth_address_to_user)
    ]
