# Generated by Django 2.0 on 2017-12-18 01:30

import crosswalk.models.user
import crosswalk.validators
from django.conf import settings
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='ApiUser',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('token', models.SlugField(default=crosswalk.models.user.ApiUser.generate_token, editable=False, max_length=20, unique=True)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='Domain',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('slug', models.SlugField(blank=True, editable=False, max_length=250, unique=True)),
                ('name', models.CharField(max_length=250, unique=True)),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='children', to='crosswalk.Domain')),
            ],
        ),
        migrations.CreateModel(
            name='Entity',
            fields=[
                ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
                ('attributes', django.contrib.postgres.fields.jsonb.JSONField(validators=[crosswalk.validators.validate_shallow_dict, crosswalk.validators.validate_no_reserved_keys])),
                ('created', models.DateTimeField(auto_now_add=True)),
                ('updated', models.DateTimeField(auto_now=True)),
                ('alias_for', models.ForeignKey(blank=True, help_text='Entity in the same domain whose UUID supersedes this one.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='aliases', to='crosswalk.Entity')),
                ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
                ('domain', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='entities', to='crosswalk.Domain')),
                ('superseded_by', models.ForeignKey(blank=True, help_text='Entity in another domain whose UUID supersedes this one.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='supersedes', to='crosswalk.Entity')),
            ],
            options={
                'verbose_name_plural': 'entities',
            },
        ),
        migrations.AlterUniqueTogether(
            name='entity',
            unique_together={('domain', 'attributes')},
        ),
    ]
