# Generated by Django 4.2.6 on 2025-04-21 03:48

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

import pghistory.utils


class Migration(migrations.Migration):
    dependencies = [
        ("pghistory", "0006_delete_aggregateevent"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("tests", "0014_customautofieldmodel_custombigautofieldmodel_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="DenormContextEventNoIdStatement",
            fields=[
                ("pgh_id", models.AutoField(primary_key=True, serialize=False)),
                ("pgh_created_at", models.DateTimeField(auto_now_add=True)),
                ("pgh_label", models.TextField(help_text="The event label.")),
                ("pgh_context", pghistory.utils.JSONField(null=True)),
                ("id", models.IntegerField()),
                ("int_field", models.IntegerField()),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="DenormContextStatement",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("int_field", models.IntegerField()),
            ],
        ),
        migrations.CreateModel(
            name="DenormContextStatementEvent",
            fields=[
                ("pgh_id", models.AutoField(primary_key=True, serialize=False)),
                ("pgh_created_at", models.DateTimeField(auto_now_add=True)),
                ("pgh_label", models.TextField(help_text="The event label.")),
                ("pgh_context", pghistory.utils.JSONField(null=True)),
                ("pgh_context_id", models.UUIDField(null=True)),
                ("id", models.IntegerField()),
                ("int_field", models.IntegerField()),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="EventModelStatement",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("dt_field", models.DateTimeField()),
                ("int_field", models.IntegerField()),
            ],
        ),
        migrations.CreateModel(
            name="EventModelStatementEvent",
            fields=[
                ("pgh_id", models.AutoField(primary_key=True, serialize=False)),
                ("pgh_created_at", models.DateTimeField(auto_now_add=True)),
                ("pgh_label", models.TextField(help_text="The event label.")),
                ("id", models.IntegerField()),
                ("dt_field", models.DateTimeField()),
                ("int_field", models.IntegerField()),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="NoPghObjEventStatement",
            fields=[
                ("pgh_id", models.AutoField(primary_key=True, serialize=False)),
                ("pgh_created_at", models.DateTimeField(auto_now_add=True)),
                ("pgh_label", models.TextField(help_text="The event label.")),
                ("id", models.IntegerField()),
                ("dt_field", models.DateTimeField()),
                ("int_field", models.IntegerField()),
            ],
            options={
                "abstract": False,
            },
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="ignoreautofieldssnapshotmodel",
            name="update_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="ignoreautofieldssnapshotmodel",
            name="delete_delete",
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="ignoreautofieldssnapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition='WHEN (OLD."my_char_field" IS DISTINCT FROM (NEW."my_char_field") OR OLD."my_int_field" IS DISTINCT FROM (NEW."my_int_field"))',  # noqa: E501
                    func='INSERT INTO "tests_ignoreautofieldssnapshotmodelcreatedatupdatedatmychardc6b" ("created_at", "my_char_field", "my_int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "updated_at") VALUES (OLD."created_at", OLD."my_char_field", OLD."my_int_field", _pgh_attach_context(), NOW(), \'update\', OLD."id", OLD."updated_at"); RETURN NULL;',  # noqa: E501
                    hash="bc2e4b046f2c8570dc9116807f33f3c09173998c",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_9dd1b",
                    table="tests_ignoreautofieldssnapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="ignoreautofieldssnapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="delete_delete",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_ignoreautofieldssnapshotmodelcreatedatupdatedatmychardc6b" ("created_at", "my_char_field", "my_int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id", "updated_at") VALUES (OLD."created_at", OLD."my_char_field", OLD."my_int_field", _pgh_attach_context(), NOW(), \'delete\', OLD."id", OLD."updated_at"); RETURN NULL;',  # noqa: E501
                    hash="aa91265c174b305edbfe6f2d2742522912503a2f",
                    operation="DELETE",
                    pgid="pgtrigger_delete_delete_42ea6",
                    table="tests_ignoreautofieldssnapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        migrations.AddField(
            model_name="nopghobjeventstatement",
            name="pgh_context",
            field=models.ForeignKey(
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                to="pghistory.context",
            ),
        ),
        migrations.AddField(
            model_name="eventmodelstatementevent",
            name="pgh_context",
            field=models.ForeignKey(
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                to="pghistory.context",
            ),
        ),
        migrations.AddField(
            model_name="eventmodelstatementevent",
            name="pgh_obj",
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="events",
                to="tests.eventmodelstatement",
            ),
        ),
        migrations.AddField(
            model_name="denormcontextstatementevent",
            name="fk_field",
            field=models.ForeignKey(
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                related_query_name="+",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="denormcontextstatementevent",
            name="pgh_obj",
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="events",
                to="tests.denormcontextstatement",
            ),
        ),
        migrations.AddField(
            model_name="denormcontextstatement",
            name="fk_field",
            field=models.ForeignKey(
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="denormcontexteventnoidstatement",
            name="fk_field",
            field=models.ForeignKey(
                db_constraint=False,
                null=True,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                related_query_name="+",
                to=settings.AUTH_USER_MODEL,
            ),
        ),
        migrations.AddField(
            model_name="denormcontexteventnoidstatement",
            name="pgh_obj",
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="event_no_id",
                to="tests.denormcontextstatement",
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodelstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="model_create_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_eventmodelstatementevent"("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT new_values."dt_field", new_values."id", new_values."int_field", _pgh_attached_context.value, NOW(), \'model.create\', new_values."id" FROM ( SELECT new_values.* FROM new_values ) AS new_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="94fda98ddedc7c54eca52ecccba50807c6105902",
                    level="STATEMENT",
                    operation="INSERT",
                    pgid="pgtrigger_model_create_insert_9bbc0",
                    referencing="REFERENCING NEW TABLE AS new_values ",
                    table="tests_eventmodelstatement",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodelstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="before_update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_eventmodelstatementevent"("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT old_values."dt_field", old_values."id", old_values."int_field", _pgh_attached_context.value, NOW(), \'before_update\', old_values."id" FROM ( SELECT old_values.* FROM old_values JOIN new_values ON (old_values."id") = (new_values."id") WHERE (old_values.* IS DISTINCT FROM new_values.*) ) AS old_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="bfb5e40f1fc069765ef43f2f4f11a70cf5afdc08",
                    level="STATEMENT",
                    operation="UPDATE",
                    pgid="pgtrigger_before_update_update_59271",
                    referencing="REFERENCING OLD TABLE AS old_values  NEW TABLE AS new_values ",
                    table="tests_eventmodelstatement",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodelstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="before_delete_delete",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_eventmodelstatementevent"("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT old_values."dt_field", old_values."id", old_values."int_field", _pgh_attached_context.value, NOW(), \'before_delete\', old_values."id" FROM ( SELECT old_values.* FROM old_values ) AS old_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="24dd83dc7c139f8f31592d095e60f9af4e269a99",
                    level="STATEMENT",
                    operation="DELETE",
                    pgid="pgtrigger_before_delete_delete_8f0bf",
                    referencing="REFERENCING OLD TABLE AS old_values ",
                    table="tests_eventmodelstatement",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodelstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="after_update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_eventmodelstatementevent"("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT new_values."dt_field", new_values."id", new_values."int_field", _pgh_attached_context.value, NOW(), \'after_update\', new_values."id" FROM ( SELECT new_values.* FROM old_values JOIN new_values ON (old_values."id") = (new_values."id") WHERE (old_values."dt_field" IS DISTINCT FROM (new_values."dt_field")) ) AS new_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="eb79eda78cd8f8446d39220d70d3d300ae10cadf",
                    level="STATEMENT",
                    operation="UPDATE",
                    pgid="pgtrigger_after_update_update_d16b9",
                    referencing="REFERENCING OLD TABLE AS old_values  NEW TABLE AS new_values ",
                    table="tests_eventmodelstatement",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontextstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_no_id_insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_denormcontexteventnoidstatement"("fk_field_id", "id", "int_field", "pgh_context", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT new_values."fk_field_id", new_values."id", new_values."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, NOW(), \'snapshot_no_id_insert\', new_values."id" FROM ( SELECT new_values.* FROM new_values ) AS new_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="e81053ee342f986285a2707d94b424395031f612",
                    level="STATEMENT",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_no_id_insert_insert_182ba",
                    referencing="REFERENCING NEW TABLE AS new_values ",
                    table="tests_denormcontextstatement",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontextstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_no_id_update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_denormcontexteventnoidstatement"("fk_field_id", "id", "int_field", "pgh_context", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT new_values."fk_field_id", new_values."id", new_values."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, NOW(), \'snapshot_no_id_update\', new_values."id" FROM ( SELECT new_values.* FROM old_values JOIN new_values ON (old_values."id") = (new_values."id") WHERE (old_values.* IS DISTINCT FROM new_values.*) ) AS new_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="5050afb4509577eb66913e934e7419d5fd6fccdc",
                    level="STATEMENT",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_no_id_update_update_6e163",
                    referencing="REFERENCING OLD TABLE AS old_values  NEW TABLE AS new_values ",
                    table="tests_denormcontextstatement",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontextstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_denormcontextstatementevent"("fk_field_id", "id", "int_field", "pgh_context", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT new_values."fk_field_id", new_values."id", new_values."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_id\', TRUE), \'\'), NULL)::UUID, NOW(), \'insert\', new_values."id" FROM ( SELECT new_values.* FROM new_values ) AS new_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="8dee862cb7a789ec95716e849cd266b4aef458a1",
                    level="STATEMENT",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_0fdb0",
                    referencing="REFERENCING NEW TABLE AS new_values ",
                    table="tests_denormcontextstatement",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontextstatement",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='WITH _pgh_attached_context AS ( SELECT _pgh_attach_context() AS value ) INSERT INTO "tests_denormcontextstatementevent"("fk_field_id", "id", "int_field", "pgh_context", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") SELECT new_values."fk_field_id", new_values."id", new_values."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_id\', TRUE), \'\'), NULL)::UUID, NOW(), \'update\', new_values."id" FROM ( SELECT new_values.* FROM old_values JOIN new_values ON (old_values."id") = (new_values."id") WHERE (old_values.* IS DISTINCT FROM new_values.*) ) AS new_values, _pgh_attached_context; RETURN NULL;',  # noqa: E501
                    hash="722d32aa53b60c57a976915dae04d3037d68042d",
                    level="STATEMENT",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_7c65e",
                    referencing="REFERENCING OLD TABLE AS old_values  NEW TABLE AS new_values ",
                    table="tests_denormcontextstatement",
                    when="AFTER",
                ),
            ),
        ),
    ]
