# Generated by Django 3.2.15 on 2022-11-25 09:42

from django.db import migrations, models

import academic_community.ckeditor5.fields


def remove_private_conversation_names(apps, schema_editor):
    """Remove the names of private conversations."""
    Channel = apps.get_model("chats", "Channel")
    Channel.objects.filter(privateconversation__isnull=False).update(name=None)


def undo_remove_private_conversation_names(apps, schema_editor):
    """Remove the names of private conversations."""
    Channel = apps.get_model("chats", "Channel")
    for channel in Channel.objects.filter(name__isnull=True):
        channel.name = channel.display_name
        channel.save()


class Migration(migrations.Migration):

    dependencies = [
        ("chats", "0004_auto_20221107_1448"),
    ]

    operations = [
        migrations.AlterField(
            model_name="channel",
            name="name",
            field=models.CharField(
                help_text="The subject of the channel.",
                max_length=200,
                null=True,
            ),
        ),
        migrations.AlterField(
            model_name="comment",
            name="body",
            field=academic_community.ckeditor5.fields.CKEditor5Field(
                help_text="The content of the comment.", null=True
            ),
        ),
        migrations.RunPython(
            remove_private_conversation_names,
            undo_remove_private_conversation_names,
        ),
    ]
