# Generated by Django 4.2.11 on 2025-01-15 10:00

from django.db import migrations, models, connection


def move_ptr_id(apps, schema_editor):
    AbstractBasePage = apps.get_model("ocyan_plugin_wagtail", "AbstractBasePage")

    for migrated_model in ["coyotehomepage", "coyotecontactpage"]:
        Model = apps.get_model("coyote", migrated_model)

        Model.objects.all().update(abstractbasepage_ptr=models.F("page_ptr"))

        with connection.cursor() as cursor:
            for p in Model.objects.all():
                cursor.execute(
                    "INSERT INTO ocyan_plugin_wagtail_abstractbasepage (page_ptr_id, search_image_id) VALUES (%s, %s)"
                    % (p.page_ptr_id, p.search_image_id or "Null")
                )


class Migration(migrations.Migration):

    dependencies = [
        ("coyote", "0022_add_abstractbasepage_fields"),
    ]

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