# Generated by Django 5.0.9 on 2024-11-01 17:41

import django.contrib.postgres.fields
import django.core.serializers.json
import django.core.validators
import django.db.migrations.operations.special
import django.db.models.deletion
import mptt.fields
import taggit.managers
from django.db import migrations, models

import utilities.json


class Migration(migrations.Migration):
    initial = True

    replaces = [
        ("netbox_data_flows", "0001_initial"),
        ("netbox_data_flows", "0002_alter_objectalias_options"),
        ("netbox_data_flows", "0003_alter_application_custom_field_data_and_more"),
        ("netbox_data_flows", "0004_reindex_netbox_data_flows"),
        ("netbox_data_flows", "0005_dataflowgroup_slug"),
        ("netbox_data_flows", "0006_reindex_netbox_data_flows"),
        ("netbox_data_flows", "0007_remove_objectalias_size"),
        ("netbox_data_flows", "0008_delete_orphaned_aliases"),
        ("netbox_data_flows", "0009_fix_empty_dfg_slugs"),
        ("netbox_data_flows", "0010_alter_objectaliastarget_options"),
        ("netbox_data_flows", "0011_objectalias_comments"),
        ("netbox_data_flows", "0012_split_objectaliastargets_into_direct_relationships"),
    ]

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
        ("extras", "0077_customlink_extend_text_and_url"),
        ("ipam", "0047_squashed_0053"),
    ]

    operations = [
        migrations.CreateModel(
            name="ApplicationRole",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("created", models.DateTimeField(auto_now_add=True, null=True)),
                ("last_updated", models.DateTimeField(auto_now=True, null=True)),
                (
                    "custom_field_data",
                    models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
                ),
                ("name", models.CharField(max_length=100, unique=True)),
                ("slug", models.SlugField(max_length=100, unique=True)),
                ("description", models.CharField(blank=True, max_length=200)),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "ordering": ("name",),
            },
        ),
        migrations.CreateModel(
            name="Application",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("created", models.DateTimeField(auto_now_add=True, null=True)),
                ("last_updated", models.DateTimeField(auto_now=True, null=True)),
                (
                    "custom_field_data",
                    models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
                ),
                ("name", models.CharField(max_length=100, unique=True)),
                ("description", models.CharField(blank=True, max_length=200)),
                ("comments", models.TextField(blank=True)),
                (
                    "role",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="applications",
                        to="netbox_data_flows.applicationrole",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "ordering": ("name",),
            },
        ),
        migrations.CreateModel(
            name="ObjectAlias",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("created", models.DateTimeField(auto_now_add=True, null=True)),
                ("last_updated", models.DateTimeField(auto_now=True, null=True)),
                (
                    "custom_field_data",
                    models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
                ),
                ("name", models.CharField(max_length=100, unique=True)),
                ("description", models.CharField(blank=True, max_length=200)),
                ("comments", models.TextField(blank=True)),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
                ("ip_addresses", models.ManyToManyField(related_name="data_flow_object_aliases", to="ipam.ipaddress")),
                ("ip_ranges", models.ManyToManyField(related_name="data_flow_object_aliases", to="ipam.iprange")),
                ("prefixes", models.ManyToManyField(related_name="data_flow_object_aliases", to="ipam.prefix")),
            ],
            options={
                "ordering": ("name",),
                "verbose_name_plural": "Object Aliases",
            },
        ),
        migrations.CreateModel(
            name="DataFlowGroup",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("created", models.DateTimeField(auto_now_add=True, null=True)),
                ("last_updated", models.DateTimeField(auto_now=True, null=True)),
                (
                    "custom_field_data",
                    models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
                ),
                ("name", models.CharField(max_length=100)),
                ("slug", models.SlugField(max_length=100)),
                ("description", models.CharField(blank=True, max_length=200)),
                ("comments", models.TextField(blank=True)),
                ("status", models.CharField(default="enabled", max_length=10)),
                ("lft", models.PositiveIntegerField(editable=False)),
                ("rght", models.PositiveIntegerField(editable=False)),
                ("tree_id", models.PositiveIntegerField(db_index=True, editable=False)),
                ("level", models.PositiveIntegerField(editable=False)),
                (
                    "application",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dataflow_groups",
                        to="netbox_data_flows.application",
                    ),
                ),
                (
                    "parent",
                    mptt.fields.TreeForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="children",
                        to="netbox_data_flows.dataflowgroup",
                    ),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "ordering": ("application", "name"),
            },
        ),
        migrations.CreateModel(
            name="DataFlow",
            fields=[
                ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
                ("created", models.DateTimeField(auto_now_add=True, null=True)),
                ("last_updated", models.DateTimeField(auto_now=True, null=True)),
                (
                    "custom_field_data",
                    models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
                ),
                ("name", models.CharField(max_length=200)),
                ("description", models.CharField(blank=True, max_length=500)),
                ("comments", models.TextField(blank=True)),
                ("status", models.CharField(default="enabled", max_length=10)),
                ("protocol", models.CharField(max_length=10)),
                (
                    "source_ports",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.PositiveIntegerField(
                            validators=[
                                django.core.validators.MinValueValidator(1),
                                django.core.validators.MaxValueValidator(65535),
                            ]
                        ),
                        blank=True,
                        null=True,
                        size=None,
                    ),
                ),
                (
                    "destination_ports",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.PositiveIntegerField(
                            validators=[
                                django.core.validators.MinValueValidator(1),
                                django.core.validators.MaxValueValidator(65535),
                            ]
                        ),
                        blank=True,
                        null=True,
                        size=None,
                    ),
                ),
                (
                    "application",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dataflows",
                        to="netbox_data_flows.application",
                    ),
                ),
                (
                    "destinations",
                    models.ManyToManyField(related_name="dataflow_destinations", to="netbox_data_flows.objectalias"),
                ),
                (
                    "group",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="dataflows",
                        to="netbox_data_flows.dataflowgroup",
                    ),
                ),
                (
                    "sources",
                    models.ManyToManyField(related_name="dataflow_sources", to="netbox_data_flows.objectalias"),
                ),
                ("tags", taggit.managers.TaggableManager(through="extras.TaggedItem", to="extras.Tag")),
            ],
            options={
                "ordering": ("application", "group", "name"),
            },
        ),
        migrations.AddConstraint(
            model_name="dataflowgroup",
            constraint=models.UniqueConstraint(
                fields=("parent", "name"), name="netbox_data_flows_dataflowgroup_parent_name"
            ),
        ),
        migrations.AddConstraint(
            model_name="dataflowgroup",
            constraint=models.UniqueConstraint(
                condition=models.Q(("parent", None)),
                fields=("application", "name"),
                name="netbox_data_flows_dataflowgroup_application_name",
            ),
        ),
    ]
