# Generated by Django 5.2.5 on 2025-08-18 11:45

from django.db import migrations

from denorm.db import const


class Migration(migrations.Migration):
    dependencies = [
        ("denorm", "0013_alter_dirtyinstance_success"),
    ]

    operations = [
        migrations.RunSQL(
            f"""
    -- Notify when record get inserted into 'django_denorm' table
    CREATE OR REPLACE FUNCTION notify_django_denorm_queue()
      RETURNS trigger AS $$
    DECLARE
    BEGIN
      PERFORM pg_notify('{const.DENORM_QUEUE_NAME}', NEW.id::text);
      RETURN NEW;
    END;
    $$ LANGUAGE plpgsql;


    CREATE OR REPLACE TRIGGER notify_django_denorm_queue
      AFTER INSERT ON denorm_dirtyinstance
      FOR EACH ROW
      EXECUTE PROCEDURE notify_django_denorm_queue();
      """,
            migrations.RunSQL.noop,
        )
    ]
