# Generated by Django 2.1 on 2019-07-02 15:27

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

import base.fields


def create_user_profiles(apps, schema_editor):
    # We get the model from the versioned app registry
    # if we directly import it, it'll be the wrong version
    User = apps.get_model('auth', 'User')
    UserProfile = apps.get_model('entities', 'UserProfile')
    db_alias = schema_editor.connection.alias
    code = 0
    for x in User.objects.using(db_alias).all():
        UserProfile.objects.create(user=x)


class Migration(migrations.Migration):
    dependencies = [
        ('targets', '0027_datasource_type'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('entities', '0002_auto_20190325_1359'),
    ]

    operations = [
        migrations.CreateModel(
            name='UserProfile',
            fields=[
                ('id',
                 models.CharField(default=base.fields.generate_id, editable=False, max_length=22, primary_key=True,
                                  serialize=False)),
                ('targets',
                 models.ManyToManyField(blank=True, related_name='_userprofile_targets_+', to='targets.Target')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile',
                                              to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.RunPython(create_user_profiles, migrations.RunPython.noop),
    ]
