# Generated by Django 2.2.10 on 2020-03-19 20:21
from django.db import connection
from django.db import migrations


def old_users():
    with connection.cursor() as cursor:
        cursor.execute("SELECT * FROM information_schema.tables where table_name=%s", ('auth_user',))
        if not cursor.rowcount:
            row = []
        else:
            cursor.execute("SELECT * FROM auth_user")
            row = cursor.fetchall()

    return row


def copy_olduser_to_newuser(apps, schema_editor):
    new_user_model = apps.get_model('users', 'User')
    for old_user in old_users():
        new_user = new_user_model()
        for i, field in enumerate(new_user._meta.fields):
            if not field.primary_key:
                setattr(new_user, field.name, old_user[i])
        new_user.save()


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(copy_olduser_to_newuser),
    ]
