<filename>commodities/migrations/0001_initial.py
# Generated by Django 3.1 on 2021-01-06 15:33
import django.core.validators
import django.db.models.deletion
from django.db import migrations
from django.db import models

import common.fields


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ("footnotes", "0001_initial"),
        ("common", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="GoodsNomenclature",
            fields=[
                (
                    "trackedmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="common.trackedmodel",
                    ),
                ),
                ("valid_between", common.fields.TaricDateTimeRangeField(db_index=True)),
                ("sid", common.fields.NumericSID()),
                (
                    "item_id",
                    models.CharField(
                        db_index=True,
                        max_length=10,
                        validators=[django.core.validators.RegexValidator("\\d{10}")],
                    ),
                ),
                (
                    "suffix",
                    models.CharField(
                        db_index=True,
                        max_length=2,
                        validators=[django.core.validators.RegexValidator("\\d{2}")],
                    ),
                ),
                ("statistical", models.BooleanField()),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("common.trackedmodel", models.Model),
        ),
        migrations.CreateModel(
            name="GoodsNomenclatureIndent",
            fields=[
                (
                    "trackedmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="common.trackedmodel",
                    ),
                ),
                ("valid_between", common.fields.TaricDateTimeRangeField(db_index=True)),
                ("sid", common.fields.NumericSID()),
                ("indent", models.PositiveIntegerField(db_index=True)),
                (
                    "indented_goods_nomenclature",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="indents",
                        to="commodities.goodsnomenclature",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("common.trackedmodel", models.Model),
        ),
        migrations.CreateModel(
            name="GoodsNomenclatureSuccessor",
            fields=[
                (
                    "trackedmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="common.trackedmodel",
                    ),
                ),
                (
                    "absorbed_into_goods_nomenclature",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="commodities.goodsnomenclature",
                    ),
                ),
                (
                    "replaced_goods_nomenclature",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="successor_links",
                        to="commodities.goodsnomenclature",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("common.trackedmodel",),
        ),
        migrations.CreateModel(
            name="GoodsNomenclatureOrigin",
            fields=[
                (
                    "trackedmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="common.trackedmodel",
                    ),
                ),
                (
                    "derived_from_goods_nomenclature",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="commodities.goodsnomenclature",
                    ),
                ),
                (
                    "new_goods_nomenclature",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="origin_links",
                        to="commodities.goodsnomenclature",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("common.trackedmodel",),
        ),
        migrations.CreateModel(
            name="GoodsNomenclatureIndentNode",
            fields=[
                ("valid_between", common.fields.TaricDateTimeRangeField(db_index=True)),
                ("depth", models.PositiveIntegerField()),
                ("numchild", models.PositiveIntegerField(default=0)),
                (
                    "path",
                    models.CharField(
                        max_length=255,
                        primary_key=True,
                        serialize=False,
                        unique=True,
                    ),
                ),
                (
                    "creating_transaction",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="goods_nomenclature_indent_nodes",
                        to="common.transaction",
                    ),
                ),
                (
                    "indent",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="nodes",
                        to="commodities.goodsnomenclatureindent",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="GoodsNomenclatureDescription",
            fields=[
                (
                    "trackedmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="common.trackedmodel",
                    ),
                ),
                ("valid_between", common.fields.TaricDateTimeRangeField(db_index=True)),
                ("sid", common.fields.NumericSID()),
                ("description", models.TextField(blank=True)),
                (
                    "described_goods_nomenclature",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="descriptions",
                        to="commodities.goodsnomenclature",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("common.trackedmodel", models.Model),
        ),
        migrations.AddField(
            model_name="goodsnomenclature",
            name="origins",
            field=models.ManyToManyField(
                related_name="_goodsnomenclature_origins_+",
                through="commodities.GoodsNomenclatureOrigin",
                to="commodities.GoodsNomenclature",
            ),
        ),
        migrations.AddField(
            model_name="goodsnomenclature",
            name="successors",
            field=models.ManyToManyField(
                related_name="_goodsnomenclature_successors_+",
                through="commodities.GoodsNomenclatureSuccessor",
                to="commodities.GoodsNomenclature",
            ),
        ),
        migrations.CreateModel(
            name="FootnoteAssociationGoodsNomenclature",
            fields=[
                (
                    "trackedmodel_ptr",
                    models.OneToOneField(
                        auto_created=True,
                        on_delete=django.db.models.deletion.CASCADE,
                        parent_link=True,
                        primary_key=True,
                        serialize=False,
                        to="common.trackedmodel",
                    ),
                ),
                ("valid_between", common.fields.TaricDateTimeRangeField(db_index=True)),
                (
                    "associated_footnote",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="footnotes.footnote",
                    ),
                ),
                (
                    "goods_nomenclature",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="commodities.goodsnomenclature",
                    ),
                ),
            ],
            options={
                "abstract": False,
                "base_manager_name": "objects",
            },
            bases=("common.trackedmodel", models.Model),
        ),
    ]
