# Generated by Django 5.2.10 on 2026-03-10 14:39

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("equity", "0005_rename_equity_valu_source_u_idx_equity_valu_source__ea3d60_idx_and_more"),
    ]

    operations = [
        migrations.CreateModel(
            name="ValuationDataQualitySnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "as_of_date",
                    models.DateField(db_index=True, unique=True, verbose_name="数据日期"),
                ),
                ("expected_stock_count", models.IntegerField(default=0, verbose_name="预期股票数")),
                ("synced_stock_count", models.IntegerField(default=0, verbose_name="同步股票数")),
                ("valid_stock_count", models.IntegerField(default=0, verbose_name="有效股票数")),
                ("coverage_ratio", models.FloatField(default=0.0, verbose_name="覆盖率")),
                ("valid_ratio", models.FloatField(default=0.0, verbose_name="有效率")),
                ("missing_pb_count", models.IntegerField(default=0, verbose_name="PB缺失数")),
                ("invalid_pb_count", models.IntegerField(default=0, verbose_name="PB非法数")),
                ("missing_pe_count", models.IntegerField(default=0, verbose_name="PE缺失数")),
                ("jump_alert_count", models.IntegerField(default=0, verbose_name="跳变告警数")),
                ("source_deviation_count", models.IntegerField(default=0, verbose_name="源偏差数")),
                (
                    "primary_source",
                    models.CharField(default="akshare", max_length=32, verbose_name="主数据源"),
                ),
                ("fallback_used_count", models.IntegerField(default=0, verbose_name="备源使用数")),
                (
                    "is_gate_passed",
                    models.BooleanField(db_index=True, default=False, verbose_name="是否通过门禁"),
                ),
                (
                    "gate_reason",
                    models.CharField(
                        blank=True, default="", max_length=255, verbose_name="门禁原因"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
            ],
            options={
                "verbose_name": "估值数据质量快照",
                "verbose_name_plural": "估值数据质量快照",
                "db_table": "equity_valuation_quality_snapshot",
                "ordering": ["-as_of_date"],
            },
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="fetched_at",
            field=models.DateTimeField(
                db_index=True, default=django.utils.timezone.now, verbose_name="抓取时间"
            ),
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="is_valid",
            field=models.BooleanField(db_index=True, default=True, verbose_name="是否有效"),
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="pe_type",
            field=models.CharField(
                db_index=True, default="dynamic", max_length=16, verbose_name="PE口径"
            ),
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="quality_flag",
            field=models.CharField(
                db_index=True, default="ok", max_length=32, verbose_name="质量标记"
            ),
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="quality_notes",
            field=models.CharField(blank=True, default="", max_length=255, verbose_name="质量说明"),
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="raw_payload_hash",
            field=models.CharField(
                blank=True, default="", max_length=64, verbose_name="原始载荷哈希"
            ),
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="source_provider",
            field=models.CharField(
                db_index=True, default="unknown", max_length=32, verbose_name="数据提供方"
            ),
        ),
        migrations.AddField(
            model_name="valuationmodel",
            name="source_updated_at",
            field=models.DateTimeField(blank=True, null=True, verbose_name="源端更新时间"),
        ),
        migrations.AddIndex(
            model_name="valuationmodel",
            index=models.Index(
                fields=["stock_code", "trade_date", "is_valid"],
                name="equity_valu_stock_c_94973f_idx",
            ),
        ),
        migrations.AddIndex(
            model_name="valuationmodel",
            index=models.Index(
                fields=["trade_date", "source_provider"], name="equity_valu_trade_d_7f2ada_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="valuationmodel",
            index=models.Index(
                fields=["quality_flag", "trade_date"], name="equity_valu_quality_3b3099_idx"
            ),
        ),
        migrations.AddIndex(
            model_name="valuationdataqualitysnapshotmodel",
            index=models.Index(
                fields=["as_of_date", "is_gate_passed"], name="equity_valu_as_of_d_e7db12_idx"
            ),
        ),
    ]
