# Generated by Django 3.1.5 on 2021-02-17 11:04

from django.db import migrations

import saleor.core.db.fields
import saleor.core.utils.editorjs


def update_empty_description_field(apps, schema_editor):
    Category = apps.get_model("product", "Category")
    CategoryTranslation = apps.get_model("product", "CategoryTranslation")
    Collection = apps.get_model("product", "Collection")
    CollectionTranslation = apps.get_model("product", "CollectionTranslation")
    Product = apps.get_model("product", "Product")
    ProductTranslation = apps.get_model("product", "ProductTranslation")

    models = [
        Category,
        CategoryTranslation,
        Collection,
        CollectionTranslation,
        Product,
        ProductTranslation,
    ]

    for model in models:
        model.objects.filter(description={}).update(description=None)


class Migration(migrations.Migration):

    dependencies = [
        ("product", "0140_auto_20210125_0905"),
    ]

    operations = [
        migrations.AlterField(
            model_name="category",
            name="description",
            field=saleor.core.db.fields.SanitizedJSONField(
                blank=True,
                null=True,
                sanitizer=saleor.core.utils.editorjs.clean_editor_js,
            ),
        ),
        migrations.AlterField(
            model_name="categorytranslation",
            name="description",
            field=saleor.core.db.fields.SanitizedJSONField(
                blank=True,
                null=True,
                sanitizer=saleor.core.utils.editorjs.clean_editor_js,
            ),
        ),
        migrations.AlterField(
            model_name="collection",
            name="description",
            field=saleor.core.db.fields.SanitizedJSONField(
                blank=True,
                null=True,
                sanitizer=saleor.core.utils.editorjs.clean_editor_js,
            ),
        ),
        migrations.AlterField(
            model_name="collectiontranslation",
            name="description",
            field=saleor.core.db.fields.SanitizedJSONField(
                blank=True,
                null=True,
                sanitizer=saleor.core.utils.editorjs.clean_editor_js,
            ),
        ),
        migrations.AlterField(
            model_name="product",
            name="description",
            field=saleor.core.db.fields.SanitizedJSONField(
                blank=True,
                null=True,
                sanitizer=saleor.core.utils.editorjs.clean_editor_js,
            ),
        ),
        migrations.AlterField(
            model_name="producttranslation",
            name="description",
            field=saleor.core.db.fields.SanitizedJSONField(
                blank=True,
                null=True,
                sanitizer=saleor.core.utils.editorjs.clean_editor_js,
            ),
        ),
        migrations.RunPython(
            update_empty_description_field,
            migrations.RunPython.noop,
        ),
    ]
