# Generated by Django 4.2.6 on 2024-06-28 00:55

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


class Migration(migrations.Migration):
    dependencies = [
        ("pghistory", "0006_delete_aggregateevent"),
        ("tests", "0009_alter_custommodelevent_pgh_obj_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="BigAutoFieldModel",
            fields=[
                ("id", models.BigAutoField(primary_key=True, serialize=False)),
            ],
        ),
        migrations.CreateModel(
            name="BigAutoFieldModelEvent",
            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.BigIntegerField()),
            ],
            options={
                "abstract": False,
            },
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="custommodel",
            name="int_field_updated",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="custommodel",
            name="insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="custommodel",
            name="update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="denormcontext",
            name="snapshot_no_id_insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="denormcontext",
            name="snapshot_no_id_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="denormcontext",
            name="insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="denormcontext",
            name="update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="model_create",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="before_delete",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="model_custom_create",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="model_custom_create_with_context",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="after_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="eventmodel",
            name="before_update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="ignoreautofieldssnapshotmodel",
            name="update",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="ignoreautofieldssnapshotmodel",
            name="delete",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotimagefield",
            name="insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="snapshotimagefield",
            name="update",
        ),
        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="insert",
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name="uniqueconstraintmodel",
            name="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_update",
                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="a6a0b9a5713e6c43f4f2aac1a09fb1f36405fc12",
                    operation="UPDATE",
                    pgid="pgtrigger_int_field_updated_update_836a0",
                    table="tests_custommodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="custommodel",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_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(),'
                        " 'insert', NEW.\"my_pk\"); RETURN NULL;"
                    ),
                    hash="bad23df7a42bfde1a656addf1f47fc5da933ff83",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_dcdb7",
                    table="tests_custommodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="custommodel",
            trigger=pgtrigger.compiler.Trigger(
                name="update_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(),'
                        " 'update', NEW.\"my_pk\"); RETURN NULL;"
                    ),
                    hash="181f59bea2ecbc8dbed698a6ae026dbb46669511",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_eedf9",
                    table="tests_custommodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_no_id_insert_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_insert', NEW.\"id\"); RETURN"
                        " NULL;"
                    ),
                    hash="3b795959f3b93e019a0d7358e417633c3c0d718b",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_no_id_insert_insert_3f44f",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_no_id_update_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_update', NEW.\"id\"); RETURN"
                        " NULL;"
                    ),
                    hash="bd13bc85c89da014b3aa5a0b168032aaa3d89756",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_no_id_update_update_cc223",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_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(), 'insert', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="c31983d805eb6b6063b2ef7cd2492d99d73eb626",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_dd828",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="denormcontext",
            trigger=pgtrigger.compiler.Trigger(
                name="update_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(), 'update', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="6d93e49a4b93a3f9cd5e4426904847bed9e70c21",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_4e96c",
                    table="tests_denormcontext",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="model_create_insert",
                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="adb5faffc67693d4f4837b924aac8ec6fa190fd9",
                    operation="INSERT",
                    pgid="pgtrigger_model_create_insert_08389",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="before_update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    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="7743482148cd23f7ca93f2a995e6b346f330a8ca",
                    operation="UPDATE",
                    pgid="pgtrigger_before_update_update_2f430",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="before_delete_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="41f9f17681f684f0130345d7fe56fa94c6c82e92",
                    operation="DELETE",
                    pgid="pgtrigger_before_delete_delete_60fdd",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="after_update_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="1b862bac86ada20f01ab296ac5b1d7d8bceb4492",
                    operation="UPDATE",
                    pgid="pgtrigger_after_update_update_79ab4",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="model_custom_create_insert",
                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="4d9232b7fa160d1814d01d18b06b8d3b03cce233",
                    operation="INSERT",
                    pgid="pgtrigger_model_custom_create_insert_7c5e4",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="eventmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="model_custom_create_with_context_insert",
                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="7e48cbafd750081a83eeba57264438746115cbac",
                    operation="INSERT",
                    pgid="pgtrigger_model_custom_create_with_context_insert_13430",
                    table="tests_eventmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="ignoreautofieldssnapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition=(
                        'WHEN (OLD."id" IS DISTINCT FROM (NEW."id") OR OLD."my_char_field" IS'
                        ' DISTINCT FROM (NEW."my_char_field") OR OLD."my_int_field" IS DISTINCT'
                        ' FROM (NEW."my_int_field"))'
                    ),
                    func=(
                        'INSERT INTO "tests_ignoreautofieldssnapshotmodelevent" ("created_at",'
                        ' "id", "my_char_field", "my_int_field", "pgh_context_id",'
                        ' "pgh_created_at", "pgh_label", "pgh_obj_id", "updated_at") VALUES'
                        ' (OLD."created_at", OLD."id", OLD."my_char_field", OLD."my_int_field",'
                        ' _pgh_attach_context(), NOW(), \'update\', OLD."id", OLD."updated_at");'
                        " RETURN NULL;"
                    ),
                    hash="0f8db9efdf74678cd49f5c45ad281bad31943e4d",
                    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_ignoreautofieldssnapshotmodelevent" ("created_at",'
                        ' "id", "my_char_field", "my_int_field", "pgh_context_id",'
                        ' "pgh_created_at", "pgh_label", "pgh_obj_id", "updated_at") VALUES'
                        ' (OLD."created_at", OLD."id", OLD."my_char_field", OLD."my_int_field",'
                        ' _pgh_attach_context(), NOW(), \'delete\', OLD."id", OLD."updated_at");'
                        " RETURN NULL;"
                    ),
                    hash="d0a5645281fba0325403744c7d8a36b403a14194",
                    operation="DELETE",
                    pgid="pgtrigger_delete_delete_42ea6",
                    table="tests_ignoreautofieldssnapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotimagefield",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func=(
                        'INSERT INTO "tests_snapshotimagefieldevent" ("id", "img_field",'
                        ' "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES'
                        ' (NEW."id", NEW."img_field", _pgh_attach_context(), NOW(), \'insert\','
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="a59955baa8d4bd37e6653bff2f259f9b763e4b52",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_b85e8",
                    table="tests_snapshotimagefield",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotimagefield",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func=(
                        'INSERT INTO "tests_snapshotimagefieldevent" ("id", "img_field",'
                        ' "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES'
                        ' (NEW."id", NEW."img_field", _pgh_attach_context(), NOW(), \'update\','
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="98bab56da76ac3223d7ec083e890c6a5f90c979a",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_569d3",
                    table="tests_snapshotimagefield",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="no_pgh_obj_snapshot_insert_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_insert'); RETURN"
                        " NULL;"
                    ),
                    hash="07556c437d62680a864d9f4833efc3c2e288f16e",
                    operation="INSERT",
                    pgid="pgtrigger_no_pgh_obj_snapshot_insert_insert_dc77d",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="no_pgh_obj_snapshot_update_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_update'); RETURN"
                        " NULL;"
                    ),
                    hash="e4580bd0b2b9f45b9abde55917125348692fb9ba",
                    operation="UPDATE",
                    pgid="pgtrigger_no_pgh_obj_snapshot_update_update_201e6",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_insert_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_insert',"
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="b3eba0e3370c5be173863757832f42c68f3a9b3f",
                    operation="INSERT",
                    pgid="pgtrigger_snapshot_insert_insert_44303",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="snapshot_update_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_update',"
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="76140e1fd96e9f85536d233a5bc06d5f92b31e55",
                    operation="UPDATE",
                    pgid="pgtrigger_snapshot_update_update_36b53",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_int_field_snapshot_insert_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_insert',"
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="7d8828d64fa7eead758231a133aaf78a49a48cf0",
                    operation="INSERT",
                    pgid="pgtrigger_dt_field_int_field_snapshot_insert_insert_8deb1",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_int_field_snapshot_update_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_update',"
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="6108d27d8c00dd656dd9c0d799f573957813ac80",
                    operation="UPDATE",
                    pgid="pgtrigger_dt_field_int_field_snapshot_update_update_da6fb",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_snapshot_insert_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_insert', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="2939b00d2d4ae7598a435110a57b1b27e7de0afe",
                    operation="INSERT",
                    pgid="pgtrigger_dt_field_snapshot_insert_insert_81d95",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="dt_field_snapshot_update_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_update', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="5d2d5a162224474dd8bf9a3b2e3943db5882481b",
                    operation="UPDATE",
                    pgid="pgtrigger_dt_field_snapshot_update_update_630e0",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="custom_snapshot_insert_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_insert', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="0e5b6085e0f3c97ecc43684f8903d9c6e7197982",
                    operation="INSERT",
                    pgid="pgtrigger_custom_snapshot_insert_insert_294de",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="snapshotmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="custom_snapshot_update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition=(
                        'WHEN (OLD."fk_field_id" IS DISTINCT FROM (NEW."fk_field_id") OR OLD."id"'
                        ' IS DISTINCT FROM (NEW."id") OR OLD."int_field" IS DISTINCT FROM'
                        ' (NEW."int_field"))'
                    ),
                    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_update', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="fab1d5836d5a916a63305c5e191115128f27b8ad",
                    operation="UPDATE",
                    pgid="pgtrigger_custom_snapshot_update_update_58fd4",
                    table="tests_snapshotmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="uniqueconstraintmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_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(), 'insert',"
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="046d56fccbf0ae1313cc05f260b478fe81518680",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_56912",
                    table="tests_uniqueconstraintmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="uniqueconstraintmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="update_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(), 'update',"
                        ' NEW."id"); RETURN NULL;'
                    ),
                    hash="1849d51acd8b4ce9516b39edc122c663723afd11",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_7e7f7",
                    table="tests_uniqueconstraintmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="usergroups",
            trigger=pgtrigger.compiler.Trigger(
                name="group_add_insert",
                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="04b8dca4b9eb07edb23a3956b92747c304c5a049",
                    operation="INSERT",
                    pgid="pgtrigger_group_add_insert_e373a",
                    table="auth_user_groups",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="usergroups",
            trigger=pgtrigger.compiler.Trigger(
                name="group_remove_delete",
                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="bed9d65c1a0ae747974e9ad67ba27e13c2910801",
                    operation="DELETE",
                    pgid="pgtrigger_group_remove_delete_2e86a",
                    table="auth_user_groups",
                    when="AFTER",
                ),
            ),
        ),
        migrations.AddField(
            model_name="bigautofieldmodelevent",
            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="bigautofieldmodelevent",
            name="pgh_obj",
            field=models.ForeignKey(
                db_constraint=False,
                on_delete=django.db.models.deletion.DO_NOTHING,
                related_name="events",
                to="tests.bigautofieldmodel",
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="bigautofieldmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="insert_insert",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func=(
                        'INSERT INTO "tests_bigautofieldmodelevent" ("id", "pgh_context_id",'
                        ' "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."id",'
                        " _pgh_attach_context(), NOW(), 'insert', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="1ccec50c7064f3619b54166b7c1c8a618adf23b1",
                    operation="INSERT",
                    pgid="pgtrigger_insert_insert_dbdfc",
                    table="tests_bigautofieldmodel",
                    when="AFTER",
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="bigautofieldmodel",
            trigger=pgtrigger.compiler.Trigger(
                name="update_update",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition="WHEN (OLD.* IS DISTINCT FROM NEW.*)",
                    func=(
                        'INSERT INTO "tests_bigautofieldmodelevent" ("id", "pgh_context_id",'
                        ' "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."id",'
                        " _pgh_attach_context(), NOW(), 'update', NEW.\"id\"); RETURN NULL;"
                    ),
                    hash="3355ccc321bf465edcf61d1a319056b6524ba1e9",
                    operation="UPDATE",
                    pgid="pgtrigger_update_update_be82b",
                    table="tests_bigautofieldmodel",
                    when="AFTER",
                ),
            ),
        ),
    ]
