# Generated by Django 5.0.9 on 2024-12-19 08:39

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


class Migration(migrations.Migration):

    dependencies = [
        ("baseapp_chats", "0004_chatroomparticipant_has_archived_room"),
    ]

    operations = [
        pgtrigger.migrations.RemoveTrigger(
            model_name="messagestatus",
            name="increment_unread_count",
        ),
        migrations.AddField(
            model_name="unreadmessagecount",
            name="marked_unread",
            field=models.BooleanField(default=False),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name="messagestatus",
            trigger=pgtrigger.compiler.Trigger(
                name="increment_unread_count",
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    condition='WHEN (NOT NEW."is_read")',
                    func="\n            INSERT INTO baseapp_chats_unreadmessagecount (room_id, profile_id, marked_unread, count)\n            VALUES ((SELECT room_id FROM baseapp_chats_message WHERE id = NEW.message_id), NEW.profile_id, False, 1)\n            ON CONFLICT (room_id, profile_id)\n            DO UPDATE SET count = baseapp_chats_unreadmessagecount.count + 1;\n            RETURN NULL;\n        ",
                    hash="e18409b9d00a1d881dabf9b7aaa8da101ac5ac28",
                    operation="INSERT",
                    pgid="pgtrigger_increment_unread_count_ec3cd",
                    table="baseapp_chats_messagestatus",
                    when="AFTER",
                ),
            ),
        ),
    ]
