# Generated by Django 4.2.27 on 2026-01-16

import pgtrigger
from django.db import migrations


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

    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 "readonly" in props:
                val = props.pop("readonly")
                # Ensure boolean
                if val is True or val == "true":
                    node.readonly = True
                    changed = True

            if "sectionsSchema" in props:
                node.sections_schema = props.pop("sectionsSchema")
                changed = True

            if "min" in props:
                node.min = str(props.pop("min"))
                changed = True

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


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

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