# Generated manually to fix pghistory timezone issue

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ("parks", "0018_auto_20250914_2103"),
    ]

    operations = [
        migrations.RunSQL(
            sql="""
            -- Drop the existing trigger function
            DROP FUNCTION IF EXISTS pgtrigger_insert_insert_66883() CASCADE;

            -- Recreate the trigger function with timezone field
            CREATE OR REPLACE FUNCTION pgtrigger_insert_insert_66883()
            RETURNS TRIGGER AS $$
            BEGIN
                INSERT INTO "parks_parkevent" (
                    "average_rating", "banner_image_id", "card_image_id", "closing_date",
                    "coaster_count", "created_at", "description", "id", "name", "opening_date",
                    "opening_year", "operating_season", "operator_id", "park_type",
                    "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id",
                    "property_owner_id", "ride_count", "search_text", "size_acres",
                    "slug", "status", "updated_at", "url", "website", "timezone"
                ) VALUES (
                    NEW."average_rating", NEW."banner_image_id", NEW."card_image_id", NEW."closing_date",
                    NEW."coaster_count", NEW."created_at", NEW."description", NEW."id", NEW."name", NEW."opening_date",
                    NEW."opening_year", NEW."operating_season", NEW."operator_id", NEW."park_type",
                    _pgh_attach_context(), NOW(), 'insert', NEW."id",
                    NEW."property_owner_id", NEW."ride_count", NEW."search_text", NEW."size_acres",
                    NEW."slug", NEW."status", NEW."updated_at", NEW."url", NEW."website", NEW."timezone"
                );
                RETURN NEW;
            END;
            $$ LANGUAGE plpgsql;

            -- Recreate the trigger
            CREATE TRIGGER pgtrigger_insert_insert_66883
                AFTER INSERT ON parks_park
                FOR EACH ROW
                EXECUTE FUNCTION pgtrigger_insert_insert_66883();
            """,
            reverse_sql="""
            -- This is irreversible, but we can drop and recreate without timezone
            DROP FUNCTION IF EXISTS pgtrigger_insert_insert_66883() CASCADE;
            """,
        ),
    ]
