# Generated by Django 3.2.19 on 2023-05-31 16:29

import django.core.serializers.json
from django.db import migrations, models
import django.db.models.deletion

# This squashed migration does a clean build of the entire entity schema. It replaces all the previous
# migrations. The reason for doing the squash was that the original initial migration was using the legacy
# jsonfield v0.9, which cannot be present, even for migrations, after Django4. So the steps I took were as follows:
# 1. swapped out the field type from jsonfield.fields.jsonfield to django.db.models.jsonfield in 0001_initial,
#    essentially pretending it had been that type from the outset
# 2. swapped out the old Django2 nomenclature to the Django3.1+ nomenclature (eliminated django.contrib.postgres)
# 3. removed the code in migration 0006 that eliminated any non-conforming records prior to enforcing a new key.
#    This is safe as obviously we have no instances that have not been migrated since 2016...
# 4. finally, ran the squash as: `python manage.py squashmigrations --squashed-name 0010_squashed entity 0001 0010`
#    to collapse the entire schema creation to CreateModel calls with no AlterModel calls required.

class Migration(migrations.Migration):
    replaces = [('entity', '0001_initial'), ('entity', '0002_entitykind_is_active'),
                ('entity', '0003_auto_20150813_2234'), ('entity', '0004_auto_20150915_1747'),
                ('entity', '0005_remove_entitygroup_entities'), ('entity', '0006_entity_relationship_unique'),
                ('entity', '0007_allentityproxy'), ('entity', '0008_auto_20180329_1934'),
                ('entity', '0009_auto_20180402_2145'), ('entity', '0010_auto_20181213_1817')]

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('contenttypes', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='EntityKind',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_index=True, max_length=256, unique=True)),
                ('display_name', models.TextField(blank=True)),
                ('is_active', models.BooleanField(default=True)),
            ],
        ),
        migrations.CreateModel(
            name='Entity',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('display_name', models.TextField(blank=True, db_index=True)),
                ('entity_id', models.IntegerField()),
                ('entity_meta', models.JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder, null=True)),
                ('is_active', models.BooleanField(db_index=True, default=True)),
                ('entity_kind', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='entity.entitykind')),
                ('entity_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='contenttypes.contenttype')),
            ],
            options={
                'unique_together': {('entity_id', 'entity_type')},
            },
        ),
        migrations.CreateModel(
            name='EntityGroup',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ],
        ),
        migrations.CreateModel(
            name='EntityGroupMembership',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('entity', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='entity.entity')),
                ('entity_group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='entity.entitygroup')),
                ('sub_entity_kind', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='entity.entitykind')),
            ],
        ),
        migrations.CreateModel(
            name='EntityRelationship',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('sub_entity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='super_relationships', to='entity.entity')),
                ('super_entity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sub_relationships', to='entity.entity')),
            ],
            options={
                'unique_together': {('sub_entity', 'super_entity')},
            },
        ),
        migrations.CreateModel(
            name='AllEntityProxy',
            fields=[
            ],
            options={
                'proxy': True,
            },
            bases=('entity.entity',),
        ),
    ]
