# Generated by Django 5.2.8 on 2025-11-24 14:45

import pgtrigger.compiler
import pgtrigger.migrations
from django.db import migrations


class Migration(migrations.Migration):

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

    operations = [
        pgtrigger.migrations.RemoveTrigger(
            model_name="message",
            name="notify_new_channels_message",
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="message",
            trigger=pgtrigger.compiler.Trigger(
                name="notify_new_channels_message",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    constraint="CONSTRAINT",
                    declare="DECLARE payload text; encoded_message text; epoch text;",
                    func="\n                    encoded_message := encode(NEW.message, 'base64');\n                    epoch := extract(epoch from NEW.expires)::text;\n                    IF octet_length(NEW.id::text) + octet_length(NEW.channel) + octet_length(epoch) + octet_length(encoded_message) + 3 < 8000 THEN\n                        payload := NEW.id::text || ':' || NEW.channel || ':' || epoch || ':' || encoded_message;\n                    ELSE\n                        payload := NEW.id::text || ':' || NEW.channel || ':' || epoch;\n                    END IF;\n\n                    PERFORM pg_notify('channels_messages', payload);\n                    RETURN NEW;\n                ",
                    hash="b86d0cf8f8062d54ade9f5e8aad147aa0263a0e7",
                    operation="INSERT",
                    pgid="pgtrigger_notify_new_channels_message_d21ae",
                    table="django_channels_postgres_message",
                    timing="DEFERRABLE INITIALLY DEFERRED",
                    when="AFTER",
                ),
            ),
        ),
    ]
