# Generated by Django 4.2.27 on 2026-01-16 08:14

import pgtrigger
from django.db import migrations


def forward(apps, schema_editor):
    FormKitSchemaNode = apps.get_model("formkit_ninja", "FormKitSchemaNode")

    # We use pgtrigger.ignore to bypass protection triggers during this data migration
    # just in case some nodes are protected.
    with pgtrigger.ignore("formkit_ninja.FormKitSchemaNode:protect_node_updates"):
        for node in FormKitSchemaNode.objects.filter(additional_props__isnull=False).iterator():
            changed = False
            props = node.additional_props
            if not isinstance(props, dict):
                continue

            if "icon" in props:
                node.icon = props.pop("icon")
                changed = True
            if "title" in props:
                node.title = props.pop("title")
                changed = True

            if changed:
                node.additional_props = props
                node.save()


class Migration(migrations.Migration):
    dependencies = [
        ("formkit_ninja", "0027_remove_formkitschemanode_insert_insert_and_more"),
    ]

    operations = [
        migrations.RunPython(forward, migrations.RunPython.noop),
    ]
