# Generated by Django 4.1 on 2022-10-06 00:27
# flake8: noqa

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


class Migration(migrations.Migration):
    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("pghistory", "0005_events_middlewareevents"),
        ("tests", "0002_auto_20220808_1420"),
    ]

    operations = [
        migrations.CreateModel(
            name="CustomEventWithContext",
            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="DenormContext",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("int_field", models.IntegerField()),
            ],
        ),
        migrations.CreateModel(
            name="DenormContextEvent",
            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="DenormContextEventNoId",
            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="CustomEventProxy",
            fields=[],
            options={
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("tests.eventmodelevent",),
        ),
        migrations.CreateModel(
            name="CustomEvents",
            fields=[],
            options={
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("pghistory.events",),
            managers=[
                ("no_objects", django.db.models.manager.Manager()),
            ],
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="custommodel",
            name="int_field_updated",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="custommodel",
            name="snapshot_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="custommodel",
            name="snapshot_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="model_create",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="before_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="before_delete",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="after_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="model_custom_create",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="no_pgh_obj_snapshot_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="no_pgh_obj_snapshot_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="snapshot_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="snapshot_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="dt_field_int_field_snapshot_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="dt_field_int_field_snapshot_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="dt_field_snapshot_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="dt_field_snapshot_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="custom_snapshot_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotmodel",
            name="custom_snapshot_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="uniqueconstraintmodel",
            name="snapshot_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="uniqueconstraintmodel",
            name="snapshot_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="usergroups",
            name="group_add",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="usergroups",
            name="group_remove",
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="custommodel",
            trigger=pgtrigger.compiler.Trigger(
                name="int_field_updated",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition='WHEN (OLD."integer_field" IS DISTINCT FROM (NEW."integer_field"))',
                    func='INSERT INTO "tests_custommodelevent" ("integer_field", "my_pk", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."integer_field", NEW."my_pk", _pgh_attach_context(), NOW(), \'int_field_updated\', NEW."my_pk"); RETURN NULL;',
                    hash="f427ffcb88213b56059b9055bbde73d6e8e31569",
                    operation="UPDATE",
                    pgid="pgtrigger_int_field_updated_a1031",
                    table="tests_custommodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="custommodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_custommodelsnapshot" ("integer_field", "my_pk", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."integer_field", NEW."my_pk", _pgh_attach_context(), NOW(), \'snapshot\', NEW."my_pk"); RETURN NULL;',
                    hash="ea6e97ef362cc952bcee7b6f712f04ace92b3ae0",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_insert_16a4e",
                    table="tests_custommodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="custommodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "tests_custommodelsnapshot" ("integer_field", "my_pk", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."integer_field", NEW."my_pk", _pgh_attach_context(), NOW(), \'snapshot\', NEW."my_pk"); RETURN NULL;',
                    hash="5a582f9ee0eaa5f4e8285ce2ad2525842cf278ae",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_update_47d37",
                    table="tests_custommodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="model_create",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_eventmodelevent" ("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NEW."id", NEW."int_field", _pgh_attach_context(), NOW(), \'model.create\', NEW."id"); RETURN NULL;',
                    hash="5d350ae78918528c0e1f9c48468536489b262413",
                    operation="INSERT",
                    pgid="pgtrigger_model_create_bc0bd",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="before_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_eventmodelevent" ("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (OLD."dt_field", OLD."id", OLD."int_field", _pgh_attach_context(), NOW(), \'before_update\', OLD."id"); RETURN NULL;',
                    hash="5f516e3c39bf7debb5f9a73b6592904135ab9da5",
                    operation="UPDATE",
                    pgid="pgtrigger_before_update_aad5f",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="before_delete",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_eventmodelevent" ("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (OLD."dt_field", OLD."id", OLD."int_field", _pgh_attach_context(), NOW(), \'before_delete\', OLD."id"); RETURN NULL;',
                    hash="1f63db5e601f13db9da8be1bfd884faaf7e04e6a",
                    operation="DELETE",
                    pgid="pgtrigger_before_delete_d022b",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="after_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition='WHEN (OLD."dt_field" IS DISTINCT FROM (NEW."dt_field"))',
                    func='INSERT INTO "tests_eventmodelevent" ("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NEW."id", NEW."int_field", _pgh_attach_context(), NOW(), \'after_update\', NEW."id"); RETURN NULL;',
                    hash="a34059f2a3f7cb3f34f672e1e1897049631e977b",
                    operation="UPDATE",
                    pgid="pgtrigger_after_update_5b8c8",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="model_custom_create",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_customeventmodel" ("dt_field", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NOW(), \'model.custom_create\', NEW."id"); RETURN NULL;',
                    hash="e8050df11c17466e96ea48242b2f05785a142744",
                    operation="INSERT",
                    pgid="pgtrigger_model_custom_create_78c73",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="model_custom_create_with_context",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_customeventwithcontext" ("dt_field", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NEW."id", NEW."int_field", _pgh_attach_context(), NOW(), \'model.custom_create_with_context\', NEW."id"); RETURN NULL;',
                    hash="281af33bd794d27c9eb6f6e0f8c59cadaa374f9a",
                    operation="INSERT",
                    pgid="pgtrigger_model_custom_create_with_context_2b610",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="no_pgh_obj_snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_nopghobjsnapshot" ("dt_field", "fk_field_id", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label") VALUES (NEW."dt_field", NEW."fk_field_id", NEW."id", NEW."int_field", _pgh_attach_context(), NOW(), \'no_pgh_obj_snapshot\'); RETURN NULL;',
                    hash="f2a163a9493a2c1a6c990e603a5e39b33ae99528",
                    operation="INSERT",
                    pgid="pgtrigger_no_pgh_obj_snapshot_insert_d3501",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="no_pgh_obj_snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "tests_nopghobjsnapshot" ("dt_field", "fk_field_id", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label") VALUES (NEW."dt_field", NEW."fk_field_id", NEW."id", NEW."int_field", _pgh_attach_context(), NOW(), \'no_pgh_obj_snapshot\'); RETURN NULL;',
                    hash="ffc9c0048c670f9a6d4d0fa88a0cc7b0363c1128",
                    operation="UPDATE",
                    pgid="pgtrigger_no_pgh_obj_snapshot_update_015b7",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_snapshotmodelsnapshot" ("dt_field", "fk_field_id", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NEW."fk_field_id", NEW."id", NEW."int_field", _pgh_attach_context(), NOW(), \'snapshot\', NEW."id"); RETURN NULL;',
                    hash="efb4176833983d7608c75df4470f16689c38d9fe",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_insert_287a7",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "tests_snapshotmodelsnapshot" ("dt_field", "fk_field_id", "id", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NEW."fk_field_id", NEW."id", NEW."int_field", _pgh_attach_context(), NOW(), \'snapshot\', NEW."id"); RETURN NULL;',
                    hash="d8dae32092200f4058032a7d7d255f566a973193",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_update_4041c",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_int_field_snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_snapshotmodeldtfieldintfieldevent" ("dt_field", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NEW."int_field", _pgh_attach_context(), NOW(), \'dt_field_int_field_snapshot\', NEW."id"); RETURN NULL;',
                    hash="685d7303c58ebf04c05b14eeda6490a576966b09",
                    operation="INSERT",
                    pgid="pgtrigger_dt_field_int_field_snapshot_insert_85480",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_int_field_snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition='WHEN (OLD."dt_field" IS DISTINCT FROM (NEW."dt_field") OR OLD."int_field" IS DISTINCT FROM (NEW."int_field"))',
                    func='INSERT INTO "tests_snapshotmodeldtfieldintfieldevent" ("dt_field", "int_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", NEW."int_field", _pgh_attach_context(), NOW(), \'dt_field_int_field_snapshot\', NEW."id"); RETURN NULL;',
                    hash="7a825bed05e4dce2aab1a4a51af23537de266da7",
                    operation="UPDATE",
                    pgid="pgtrigger_dt_field_int_field_snapshot_update_8246d",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_snapshotmodeldtfieldevent" ("dt_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", _pgh_attach_context(), NOW(), \'dt_field_snapshot\', NEW."id"); RETURN NULL;',
                    hash="53f21a43f3c426cf97087eeb06a6ed1270bb6a33",
                    operation="INSERT",
                    pgid="pgtrigger_dt_field_snapshot_insert_f46b8",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition='WHEN (OLD."dt_field" IS DISTINCT FROM (NEW."dt_field"))',
                    func='INSERT INTO "tests_snapshotmodeldtfieldevent" ("dt_field", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."dt_field", _pgh_attach_context(), NOW(), \'dt_field_snapshot\', NEW."id"); RETURN NULL;',
                    hash="d4200e362d70ee8a3d90968b7d66f1faeee08e18",
                    operation="UPDATE",
                    pgid="pgtrigger_dt_field_snapshot_update_22f55",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="custom_snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_customsnapshotmodel" ("fk_field_id", "id", "int_field", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."fk_field_id", NEW."id", NEW."int_field", NOW(), \'custom_snapshot\', NEW."id"); RETURN NULL;',
                    hash="589e0126974e6cd052906ed20829c2a28c7c9faa",
                    operation="INSERT",
                    pgid="pgtrigger_custom_snapshot_insert_6d300",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="custom_snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition='WHEN (OLD."id" IS DISTINCT FROM (NEW."id") OR OLD."int_field" IS DISTINCT FROM (NEW."int_field") OR OLD."fk_field_id" IS DISTINCT FROM (NEW."fk_field_id"))',
                    func='INSERT INTO "tests_customsnapshotmodel" ("fk_field_id", "id", "int_field", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."fk_field_id", NEW."id", NEW."int_field", NOW(), \'custom_snapshot\', NEW."id"); RETURN NULL;',
                    hash="88d880fe4785b823fd0bcc32a85a58c8deb389b6",
                    operation="UPDATE",
                    pgid="pgtrigger_custom_snapshot_update_5af3e",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="uniqueconstraintmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_uniqueconstraintmodelevent" ("id", "my_char_field", "my_int_field1", "my_int_field2", "my_one_to_one_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."id", NEW."my_char_field", NEW."my_int_field1", NEW."my_int_field2", NEW."my_one_to_one_id", _pgh_attach_context(), NOW(), \'snapshot\', NEW."id"); RETURN NULL;',
                    hash="4581b70b015ec980e1f735c45ca02014cedce673",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_insert_ed815",
                    table="tests_uniqueconstraintmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="uniqueconstraintmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "tests_uniqueconstraintmodelevent" ("id", "my_char_field", "my_int_field1", "my_int_field2", "my_one_to_one_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."id", NEW."my_char_field", NEW."my_int_field1", NEW."my_int_field2", NEW."my_one_to_one_id", _pgh_attach_context(), NOW(), \'snapshot\', NEW."id"); RETURN NULL;',
                    hash="a028481331531f399b592ca634d409bb21892cdb",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_update_9e83c",
                    table="tests_uniqueconstraintmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="usergroups",
            trigger=pgtrigger.compiler.Trigger(
                name="group_add",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_usergroupsevent" ("group_id", "id", "pgh_context_id", "pgh_created_at", "pgh_label", "user_id") VALUES (NEW."group_id", NEW."id", _pgh_attach_context(), NOW(), \'group.add\', NEW."user_id"); RETURN NULL;',
                    hash="a2f18ef00bcad3fad2f68a89dde18ad17ca4022c",
                    operation="INSERT",
                    pgid="pgtrigger_group_add_9d386",
                    table="auth_user_groups",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="usergroups",
            trigger=pgtrigger.compiler.Trigger(
                name="group_remove",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_usergroupsevent" ("group_id", "id", "pgh_context_id", "pgh_created_at", "pgh_label", "user_id") VALUES (OLD."group_id", OLD."id", _pgh_attach_context(), NOW(), \'group.remove\', OLD."user_id"); RETURN NULL;',
                    hash="5ac3c434d94dbe50d890ab27134248197af1e392",
                    operation="DELETE",
                    pgid="pgtrigger_group_remove_4d892",
                    table="auth_user_groups",
                    when="AFTER",
                ),
            ),
        ),
        migrations.AddField(
            model_name="denormcontexteventnoid",
            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="denormcontexteventnoid",
            name="pgh_obj",
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="event_no_id",
                to="tests.denormcontext",
            ),
        ),
        migrations.AddField(
            model_name="denormcontextevent",
            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="denormcontextevent",
            name="pgh_obj",
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="event",
                to="tests.denormcontext",
            ),
        ),
        migrations.AddField(
            model_name="denormcontext",
            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="customeventwithcontext",
            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="customeventwithcontext",
            name="pgh_obj",
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="+",
                to="tests.eventmodel",
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_no_id_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_denormcontexteventnoid" ("fk_field_id", "id", "int_field", "pgh_context", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."fk_field_id", NEW."id", NEW."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, NOW(), \'snapshot_no_id\', NEW."id"); RETURN NULL;',
                    hash="43e6b33dddadd595d545bf50b36c9fe33245aba3",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_no_id_insert_f9f15",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_no_id_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "tests_denormcontexteventnoid" ("fk_field_id", "id", "int_field", "pgh_context", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."fk_field_id", NEW."id", NEW."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, NOW(), \'snapshot_no_id\', NEW."id"); RETURN NULL;',
                    hash="eee44ab5d3d5385f9c3802e9b5b45c5b929f4419",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_no_id_update_3c605",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO "tests_denormcontextevent" ("fk_field_id", "id", "int_field", "pgh_context", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."fk_field_id", NEW."id", NEW."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_id\', TRUE), \'\'), NULL)::UUID, NOW(), \'snapshot\', NEW."id"); RETURN NULL;',
                    hash="2f030029a5e7d9f99a1f710fecda77c025c6959c",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_insert_37e9f",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func='INSERT INTO "tests_denormcontextevent" ("fk_field_id", "id", "int_field", "pgh_context", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."fk_field_id", NEW."id", NEW."int_field", COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_metadata\', TRUE), \'\'), NULL)::JSONB, COALESCE(NULLIF(CURRENT_SETTING(\'pghistory.context_id\', TRUE), \'\'), NULL)::UUID, NOW(), \'snapshot\', NEW."id"); RETURN NULL;',
                    hash="09b8933b1e0d23261751066cab4180c9afd09e7b",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_update_ca16a",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
    ]
