# Generated by Django 3.2.24 on 2024-03-07 13:38

from django.db import migrations, models


MIGRATE_FORWARD_MUTED_MESSAGE = """
UPDATE msgs_supportgroupmessagerecipient r 
  SET muted = true
  FROM msgs_supportgroupmessage_recipient_mutedlist ml
  WHERE ml.supportgroupmessage_id = r.message_id
  AND ml.person_id = r.recipient_id;
"""

MIGRATE_BACKWARD_MUTED_MESSAGE = """
INSERT INTO msgs_supportgroupmessage_recipient_mutedlist (supportgroupmessage_id, person_id)
(SELECT
   message_id,
   recipient_id
 FROM msgs_supportgroupmessagerecipient
 WHERE muted = true
);
"""


class Migration(migrations.Migration):
    dependencies = [
        ("msgs", "0012_auto_20240119_1040"),
    ]

    operations = [
        migrations.AddField(
            model_name="supportgroupmessagerecipient",
            name="muted",
            field=models.BooleanField(default=False, verbose_name="En sourdine"),
        ),
        migrations.RunSQL(
            sql=MIGRATE_FORWARD_MUTED_MESSAGE,
            reverse_sql=MIGRATE_BACKWARD_MUTED_MESSAGE,
        ),
        migrations.RemoveField(
            model_name="supportgroupmessage",
            name="recipient_mutedlist",
        ),
    ]
