# Generated by Django 4.2.23 on 2025-09-22 04:41

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ("extracts", "0021_add_extract_filtering_indexes"),
    ]

    operations = [
        # Datacell queries
        migrations.RunSQL(
            "CREATE INDEX IF NOT EXISTS idx_datacell_extract_doc "
            "ON extracts_datacell(extract_id, document_id);",
            reverse_sql="DROP INDEX IF EXISTS idx_datacell_extract_doc;",
        ),
        migrations.RunSQL(
            "CREATE INDEX IF NOT EXISTS idx_datacell_column "
            "ON extracts_datacell(column_id, extract_id);",
            reverse_sql="DROP INDEX IF EXISTS idx_datacell_column;",
        ),
        migrations.RunSQL(
            "CREATE INDEX IF NOT EXISTS idx_datacell_approved "
            "ON extracts_datacell(extract_id, approved_by_id) "
            "WHERE approved_by_id IS NOT NULL;",
            reverse_sql="DROP INDEX IF EXISTS idx_datacell_approved;",
        ),
        migrations.RunSQL(
            "CREATE INDEX IF NOT EXISTS idx_datacell_rejected "
            "ON extracts_datacell(extract_id, rejected_by_id) "
            "WHERE rejected_by_id IS NOT NULL;",
            reverse_sql="DROP INDEX IF EXISTS idx_datacell_rejected;",
        ),
        # Extract patterns
        migrations.RunSQL(
            "CREATE INDEX IF NOT EXISTS idx_extract_corpus "
            "ON extracts_extract(corpus_id, creator_id);",
            reverse_sql="DROP INDEX IF EXISTS idx_extract_corpus;",
        ),
        migrations.RunSQL(
            "CREATE INDEX IF NOT EXISTS idx_extract_finished "
            "ON extracts_extract(corpus_id, finished) "
            "WHERE finished IS NOT NULL;",
            reverse_sql="DROP INDEX IF EXISTS idx_extract_finished;",
        ),
    ]
