# Generated by Django 4.1.8 on 2023-04-06 06:43

import django.contrib.postgres.fields
import django.contrib.postgres.indexes
import django.contrib.postgres.search
import django.db.models.deletion
import mptt.fields
import timezone_field.fields
from django.contrib.postgres.operations import BtreeGinExtension, TrigramExtension
from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        TrigramExtension(),
        BtreeGinExtension(),
        migrations.CreateModel(
            name="Geography",
            fields=[
                (
                    "id",
                    models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID"),
                ),
                ("name", models.CharField(max_length=255)),
                ("short_name", models.CharField(max_length=255)),
                (
                    "alternative_names",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.CharField(max_length=255),
                        blank=True,
                        default=list,
                        help_text="Alternative Names",
                        size=None,
                        verbose_name="Alternative Names",
                    ),
                ),
                ("representation", models.CharField(blank=True, default="", max_length=255)),
                ("search_vector", django.contrib.postgres.search.SearchVectorField(null=True)),
                ("trigram_search_vector", models.CharField(blank=True, max_length=1024, null=True)),
                (
                    "code_2",
                    models.CharField(
                        blank=True, max_length=2, null=True, verbose_name="2 Character Alphanumeric Code"
                    ),
                ),
                (
                    "code_3",
                    models.CharField(
                        blank=True, max_length=3, null=True, verbose_name="3 Character Alphanumeric Code"
                    ),
                ),
                ("code", models.CharField(blank=True, max_length=16, null=True, verbose_name="Code")),
                ("population", models.PositiveIntegerField(blank=True, null=True)),
                ("ranking", models.PositiveIntegerField(default=1)),
                (
                    "time_zone",
                    timezone_field.fields.TimeZoneField(blank=True, choices_display="WITH_GMT_OFFSET", null=True),
                ),
                ("lft", models.PositiveIntegerField(editable=False)),
                ("rght", models.PositiveIntegerField(editable=False)),
                ("tree_id", models.PositiveIntegerField(db_index=True, editable=False)),
                ("level", models.PositiveIntegerField(editable=False)),
                (
                    "parent",
                    mptt.fields.TreeForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="children",
                        to="geography.geography",
                    ),
                ),
            ],
            options={
                "verbose_name_plural": "Geographies",
            },
        ),
        migrations.AddIndex(
            model_name="geography",
            index=django.contrib.postgres.indexes.GinIndex(fields=["search_vector"], name="geography_sv_gin_idx"),
        ),
        migrations.AddIndex(
            model_name="geography",
            index=django.contrib.postgres.indexes.GinIndex(
                fields=["trigram_search_vector"],
                name="geography_trigram_sv_gin_idx",
                opclasses=["gin_trgm_ops"],
            ),
        ),
        migrations.AddConstraint(
            model_name="geography",
            constraint=models.UniqueConstraint(
                condition=models.Q(("level", 1)),
                fields=("level", "code_2"),
                name="geography_geography_level_code2__uniq",
            ),
        ),
        migrations.AddConstraint(
            model_name="geography",
            constraint=models.UniqueConstraint(
                condition=models.Q(("level", 1)),
                fields=("level", "code_3"),
                name="geography_geography_level_code3__uniq",
            ),
        ),
    ]
