# Copyright 2025 Laurent Defert
#
#  This file is part of Sosse.
#
# Sosse is free software: you can redistribute it and/or modify it under the terms of the GNU Affero
# General Public License as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Sosse is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License along with Sosse.
# If not, see <https://www.gnu.org/licenses/>.

# Generated by Django 4.2.23 on 2025-09-29 12:04

from django.db import migrations


def save_mime_plugins(apps, schema_editor):
    """Call save() on each MimePlugin to write scripts to disk."""
    MimePlugin = apps.get_model("se", "MimePlugin")
    for plugin in MimePlugin.objects.all():
        plugin.save()


def reverse_save_mime_plugins(apps, schema_editor):
    """Reverse operation - nothing to do."""
    pass


class Migration(migrations.Migration):
    dependencies = [
        ("se", "0022_make_collection_non_null"),
    ]

    operations = [
        migrations.RenameModel(
            old_name="MimeHandler",
            new_name="MimePlugin",
        ),
        migrations.RenameField(
            model_name="document",
            old_name="mime_handlers_result",
            new_name="mime_plugins_result",
        ),
        migrations.RunPython(
            save_mime_plugins,
            reverse_save_mime_plugins,
        ),
    ]
