# Generated by Django 3.2.7 on 2021-10-03 06:18

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


class Migration(migrations.Migration):

    replaces = [
        ("denorm", "0001_initial"),
        ("denorm", "0002_dirtyinstance_func_name"),
        ("denorm", "0003_auto_20211002_1955"),
        ("denorm", "0004_alter_dirtyinstance_success"),
        ("denorm", "0005_dirtyinstance_created_on"),
        ("denorm", "0006_auto_20211003_0346"),
        ("denorm", "0007_auto_created_on_now"),
        ("denorm", "0008_alter_dirtyinstance_object_id"),
        ("denorm", "0009_alter_dirtyinstance_object_id"),
        ("denorm", "0010_alter_dirtyinstance_object_id"),
        ("denorm", "0011_alter_dirtyinstance_object_id"),
        ("denorm", "0012_alter_dirtyinstance_object_id"),
    ]

    initial = True

    dependencies = [
        ("contenttypes", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="DirtyInstance",
            fields=[
                (
                    "id",
                    models.AutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("object_id", models.TextField(blank=True, null=True)),
                (
                    "content_type",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        to="contenttypes.contenttype",
                    ),
                ),
            ],
        ),
        migrations.RunSQL(
            sql="\n        -- Notify when record get inserted into 'django_denorm' table\n"
            "        CREATE OR REPLACE FUNCTION notify_django_denorm_queue()\n"
            "          RETURNS trigger AS $$\n        DECLARE\n        BEGIN\n"
            "          PERFORM pg_notify('django_denorm_process', '');\n          RETURN NEW;\n"
            "        END;\n        $$ LANGUAGE plpgsql;\n\n        "
            "CREATE TRIGGER notify_django_denorm_queue\n          AFTER INSERT ON denorm_dirtyinstance\n"
            "          FOR EACH STATEMENT\n          EXECUTE PROCEDURE notify_django_denorm_queue();\n"
            "        ",
            reverse_sql="\n            DROP TRIGGER notify_django_denorm_queue ON denorm_dirtyinstance;\n     "
            "       DROP FUNCTION notify_django_denorm_queue;\n            ",
        ),
        migrations.AddField(
            model_name="dirtyinstance",
            name="processing_finished",
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name="dirtyinstance",
            name="traceback",
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name="dirtyinstance",
            name="created_on",
            field=models.DateTimeField(auto_now_add=True, db_index=True),
        ),
        migrations.AddField(
            model_name="dirtyinstance",
            name="func_name",
            field=models.TextField(blank=True, db_index=True, null=True),
        ),
        migrations.AlterField(
            model_name="dirtyinstance",
            name="object_id",
            field=models.IntegerField(db_index=True, default=0),
            preserve_default=False,
        ),
        migrations.AddField(
            model_name="dirtyinstance",
            name="processing_started",
            field=models.DateTimeField(blank=True, db_index=True, null=True),
        ),
        migrations.AddField(
            model_name="dirtyinstance",
            name="success",
            field=models.NullBooleanField(db_index=True),
        ),
        migrations.RunSQL(
            sql="ALTER TABLE denorm_dirtyinstance ALTER COLUMN created_on SET DEFAULT CURRENT_TIMESTAMP",
            reverse_sql="",
        ),
        migrations.AlterField(
            model_name="dirtyinstance",
            name="object_id",
            field=models.IntegerField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="dirtyinstance",
            name="object_id",
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="dirtyinstance",
            name="object_id",
            field=models.IntegerField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="dirtyinstance",
            name="object_id",
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AlterField(
            model_name="dirtyinstance",
            name="object_id",
            field=models.IntegerField(blank=True, null=True),
        ),
    ]
