# Generated by Django - CorpusQuery deprecation migration

from django.db import migrations


class Migration(migrations.Migration):
    """
    Remove the deprecated CorpusQuery model and its related tables.

    CorpusQuery was an old one-shot query system that has been superseded
    by the Conversation/ChatMessage system which supports threading,
    multi-turn conversations, and more advanced features.

    This migration drops:
    - corpuses_corpusquery (main table)
    - corpuses_corpusquery_sources (M2M through table)
    - corpuses_corpusqueryuserobjectpermission (guardian permissions)
    - corpuses_corpusquerygroupobjectpermission (guardian permissions)
    """

    dependencies = [
        ("corpuses", "0032_add_thread_message_triggers"),
    ]

    operations = [
        # Drop the M2M through table first (sources relationship)
        migrations.RunSQL(
            sql="DROP TABLE IF EXISTS corpuses_corpusquery_sources CASCADE;",
            reverse_sql=migrations.RunSQL.noop,
        ),
        # Drop the guardian permission tables
        migrations.RunSQL(
            sql="DROP TABLE IF EXISTS corpuses_corpusqueryuserobjectpermission CASCADE;",
            reverse_sql=migrations.RunSQL.noop,
        ),
        migrations.RunSQL(
            sql="DROP TABLE IF EXISTS corpuses_corpusquerygroupobjectpermission CASCADE;",
            reverse_sql=migrations.RunSQL.noop,
        ),
        # Drop the main CorpusQuery table
        migrations.RunSQL(
            sql="DROP TABLE IF EXISTS corpuses_corpusquery CASCADE;",
            reverse_sql=migrations.RunSQL.noop,
        ),
    ]
