# Generated by Django 4.2.6 on 2023-10-28 23:13

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

SENTINEL_NULL_TRANSACTION_ID = getattr(settings, "SENTINEL_NULL_TRANSACTION_ID", 1)


def add_sentinel(apps, schema_editor):
    Transaction = apps.get_model("django_anchor_modeling", "Transaction")
    Transaction.objects.get_or_create(pk=SENTINEL_NULL_TRANSACTION_ID)


def remove_sentinel(apps, schema_editor):
    Transaction = apps.get_model("django_anchor_modeling", "Transaction")
    Transaction.objects.filter(pk=SENTINEL_NULL_TRANSACTION_ID).delete()


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("contenttypes", "0002_remove_content_type_name"),
    ]

    operations = [
        migrations.CreateModel(
            name="Transaction",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="HistorizedModelMap",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                (
                    "active_model",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="historized_map_active",
                        to="contenttypes.contenttype",
                    ),
                ),
                (
                    "historized_model",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="historized_map_historized",
                        to="contenttypes.contenttype",
                    ),
                ),
            ],
        ),
        migrations.RunPython(add_sentinel, remove_sentinel),
    ]
