from django.db import migrations, models


class Migration(migrations.Migration):

    # resm_paper 现有数百万行；质量状态索引用 CONCURRENTLY 创建，避免长时间阻塞写入。
    atomic = False

    dependencies = [
        ("resm", "0011_seed_briefing_monitors"),
    ]

    operations = [
        migrations.AddField(
            model_name="paper",
            name="title_raw",
            field=models.TextField(blank=True, null=True),
        ),
        migrations.AddField(
            model_name="paper",
            name="title_source",
            field=models.CharField(blank=True, max_length=30, null=True),
        ),
        migrations.SeparateDatabaseAndState(
            database_operations=[
                migrations.AddField(
                    model_name="paper",
                    name="title_quality_status",
                    field=models.CharField(
                        choices=[
                            ("unchecked", "未检查"),
                            ("suspect", "疑似异常"),
                            ("verified", "已验证"),
                            ("corrected", "已矫正"),
                        ],
                        default="unchecked",
                        max_length=20,
                    ),
                ),
            ],
            state_operations=[
                migrations.AddField(
                    model_name="paper",
                    name="title_quality_status",
                    field=models.CharField(
                        choices=[
                            ("unchecked", "未检查"),
                            ("suspect", "疑似异常"),
                            ("verified", "已验证"),
                            ("corrected", "已矫正"),
                        ],
                        db_index=True,
                        default="unchecked",
                        max_length=20,
                    ),
                ),
            ],
        ),
        migrations.RunSQL(
            sql=(
                "CREATE INDEX CONCURRENTLY IF NOT EXISTS "
                "resm_paper_title_quality_status_idx "
                "ON resm_paper (title_quality_status);"
            ),
            reverse_sql=(
                "DROP INDEX CONCURRENTLY IF EXISTS "
                "resm_paper_title_quality_status_idx;"
            ),
        ),
        migrations.AddField(
            model_name="paper",
            name="title_verified_at",
            field=models.DateTimeField(blank=True, null=True),
        ),
    ]
