# Generated manually for enhanced filtering performance

from django.db import migrations


class Migration(migrations.Migration):
    atomic = False  # Required for CREATE INDEX CONCURRENTLY

    dependencies = [
        ("parks", "0001_initial"),  # Adjust this to the latest migration
    ]

    operations = [
        # Add indexes for commonly filtered fields
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_status_idx ON parks_park (status);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_status_idx;",
        ),
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_operator_id_idx ON parks_park (operator_id);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_operator_id_idx;",
        ),
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_average_rating_idx ON parks_park (average_rating);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_average_rating_idx;",
        ),
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_size_acres_idx ON parks_park (size_acres);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_size_acres_idx;",
        ),
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_coaster_count_idx ON parks_park (coaster_count);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_coaster_count_idx;",
        ),
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_ride_count_idx ON parks_park (ride_count);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_ride_count_idx;",
        ),
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_updated_at_idx ON parks_park (updated_at);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_updated_at_idx;",
        ),
        # Composite indexes for common filter combinations
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_status_rating_idx ON parks_park (status, average_rating);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_status_rating_idx;",
        ),
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_operator_status_idx ON parks_park (operator_id, status);",
            reverse_sql="DROP INDEX IF EXISTS parks_park_operator_status_idx;",
        ),
        # Index for parks with coasters (coaster_count > 0)
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_has_coasters_idx ON parks_park (coaster_count) WHERE coaster_count > 0;",
            reverse_sql="DROP INDEX IF EXISTS parks_park_has_coasters_idx;",
        ),
        # Index for big parks (ride_count >= 10)
        migrations.RunSQL(
            "CREATE INDEX CONCURRENTLY IF NOT EXISTS parks_park_big_parks_idx ON parks_park (ride_count) WHERE ride_count >= 10;",
            reverse_sql="DROP INDEX IF EXISTS parks_park_big_parks_idx;",
        ),
    ]
