# Generated by Django 5.2.10 on 2026-02-05 15:47

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name="AlphaScoreCacheModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "universe_id",
                    models.CharField(db_index=True, help_text="股票池标识", max_length=50),
                ),
                ("intended_trade_date", models.DateField(db_index=True, help_text="计划交易日期")),
                (
                    "provider_source",
                    models.CharField(
                        choices=[
                            ("qlib", "Qlib"),
                            ("simple", "Simple"),
                            ("etf", "ETF Fallback"),
                            ("cache", "Cache"),
                        ],
                        db_index=True,
                        help_text="提供者来源",
                        max_length=20,
                    ),
                ),
                ("asof_date", models.DateField(db_index=True, help_text="信号真实生成日期")),
                (
                    "model_id",
                    models.CharField(blank=True, help_text="模型标识", max_length=200, null=True),
                ),
                (
                    "model_artifact_hash",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="模型文件哈希",
                        max_length=64,
                        null=True,
                    ),
                ),
                (
                    "feature_set_id",
                    models.CharField(blank=True, help_text="特征集标识", max_length=50, null=True),
                ),
                (
                    "label_id",
                    models.CharField(blank=True, help_text="标签标识", max_length=50, null=True),
                ),
                (
                    "data_version",
                    models.CharField(blank=True, help_text="数据版本", max_length=50, null=True),
                ),
                (
                    "scores",
                    models.JSONField(
                        help_text="评分结果 [{code, score, rank, factors, confidence}, ...]"
                    ),
                ),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("available", "可用"),
                            ("degraded", "降级"),
                            ("unavailable", "不可用"),
                        ],
                        default="available",
                        help_text="状态",
                        max_length=20,
                    ),
                ),
                ("metrics_snapshot", models.JSONField(blank=True, help_text="指标快照", null=True)),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, help_text="创建时间"),
                ),
                ("updated_at", models.DateTimeField(auto_now=True, help_text="更新时间")),
            ],
            options={
                "verbose_name": "Alpha 评分缓存",
                "verbose_name_plural": "Alpha 评分缓存",
                "db_table": "alpha_score_cache",
                "ordering": ["-intended_trade_date", "-created_at"],
                "indexes": [
                    models.Index(
                        fields=["universe_id", "intended_trade_date"],
                        name="alpha_score_univers_7ebbe2_idx",
                    ),
                    models.Index(
                        fields=["provider_source", "status"], name="alpha_score_provide_e319e6_idx"
                    ),
                    models.Index(fields=["asof_date"], name="alpha_score_asof_da_d40500_idx"),
                ],
                "unique_together": {
                    ("universe_id", "intended_trade_date", "provider_source", "model_artifact_hash")
                },
            },
        ),
        migrations.CreateModel(
            name="QlibModelRegistryModel",
            fields=[
                (
                    "model_name",
                    models.CharField(db_index=True, help_text="模型名称", max_length=100),
                ),
                (
                    "artifact_hash",
                    models.CharField(
                        help_text="模型文件哈希",
                        max_length=64,
                        primary_key=True,
                        serialize=False,
                        unique=True,
                    ),
                ),
                (
                    "model_type",
                    models.CharField(
                        choices=[
                            ("LGBModel", "LightGBM"),
                            ("LSTMModel", "LSTM"),
                            ("TransformerModel", "Transformer"),
                            ("MLPModel", "MLP"),
                        ],
                        help_text="模型类型",
                        max_length=30,
                    ),
                ),
                ("universe", models.CharField(help_text="股票池", max_length=20)),
                ("train_config", models.JSONField(help_text="训练配置")),
                ("feature_set_id", models.CharField(help_text="特征集标识", max_length=50)),
                ("label_id", models.CharField(help_text="标签标识", max_length=50)),
                ("data_version", models.CharField(help_text="数据版本", max_length=50)),
                (
                    "ic",
                    models.DecimalField(
                        blank=True, decimal_places=6, help_text="IC 值", max_digits=10, null=True
                    ),
                ),
                (
                    "icir",
                    models.DecimalField(
                        blank=True, decimal_places=6, help_text="ICIR 值", max_digits=10, null=True
                    ),
                ),
                (
                    "rank_ic",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="Rank IC 值",
                        max_digits=10,
                        null=True,
                    ),
                ),
                ("model_path", models.CharField(help_text="模型文件路径", max_length=500)),
                (
                    "is_active",
                    models.BooleanField(db_index=True, default=False, help_text="是否激活"),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, help_text="创建时间")),
                ("activated_at", models.DateTimeField(blank=True, help_text="激活时间", null=True)),
                (
                    "activated_by",
                    models.CharField(blank=True, help_text="激活者", max_length=100, null=True),
                ),
            ],
            options={
                "verbose_name": "Qlib 模型注册",
                "verbose_name_plural": "Qlib 模型注册",
                "db_table": "qlib_model_registry",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(
                        fields=["model_name", "is_active"], name="qlib_model__model_n_c4cf02_idx"
                    ),
                    models.Index(fields=["universe"], name="qlib_model__univers_9b4fa5_idx"),
                    models.Index(fields=["model_type"], name="qlib_model__model_t_8396cc_idx"),
                ],
            },
        ),
    ]
