# Generated by Django 5.2.12 on 2026-04-05 07:54

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("data_center", "0002_migrate_from_macro"),
    ]

    operations = [
        migrations.CreateModel(
            name="IndicatorCatalogModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        db_index=True,
                        help_text="Canonical indicator code (e.g. CN_GDP)",
                        max_length=50,
                        unique=True,
                    ),
                ),
                ("name_cn", models.CharField(help_text="中文名称", max_length=100)),
                ("name_en", models.CharField(blank=True, max_length=100)),
                ("description", models.TextField(blank=True)),
                (
                    "default_unit",
                    models.CharField(blank=True, help_text="e.g. 亿元, %, bps", max_length=20),
                ),
                (
                    "default_period_type",
                    models.CharField(
                        choices=[
                            ("D", "日"),
                            ("W", "周"),
                            ("M", "月"),
                            ("Q", "季度"),
                            ("H", "半年"),
                            ("Y", "年"),
                        ],
                        default="M",
                        max_length=1,
                    ),
                ),
                (
                    "category",
                    models.CharField(
                        blank=True,
                        help_text="e.g. growth, inflation, money, trade, financial",
                        max_length=30,
                    ),
                ),
                ("is_active", models.BooleanField(default=True)),
                ("extra", models.JSONField(blank=True, default=dict)),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Indicator Catalog",
                "verbose_name_plural": "Indicator Catalog",
                "db_table": "data_center_indicator_catalog",
                "ordering": ["code"],
            },
        ),
        migrations.CreateModel(
            name="AssetMasterModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "code",
                    models.CharField(
                        db_index=True,
                        help_text="Canonical ticker (Tushare format, e.g. 600519.SH)",
                        max_length=20,
                        unique=True,
                    ),
                ),
                ("name", models.CharField(help_text="Full security name", max_length=100)),
                (
                    "short_name",
                    models.CharField(blank=True, help_text="Display short name", max_length=30),
                ),
                (
                    "asset_type",
                    models.CharField(
                        choices=[
                            ("stock", "股票"),
                            ("etf", "ETF"),
                            ("index", "指数"),
                            ("fund", "基金"),
                            ("bond", "债券"),
                            ("futures", "期货"),
                            ("crypto", "加密货币"),
                            ("other", "其他"),
                        ],
                        max_length=10,
                    ),
                ),
                (
                    "exchange",
                    models.CharField(
                        choices=[
                            ("SSE", "上交所"),
                            ("SZSE", "深交所"),
                            ("BSE", "北交所"),
                            ("HKEX", "港交所"),
                            ("NYSE", "纽交所"),
                            ("NASDAQ", "纳斯达克"),
                            ("OTHER", "其他"),
                        ],
                        max_length=10,
                    ),
                ),
                ("is_active", models.BooleanField(default=True)),
                (
                    "list_date",
                    models.DateField(blank=True, help_text="IPO / listing date", null=True),
                ),
                ("delist_date", models.DateField(blank=True, null=True)),
                ("sector", models.CharField(blank=True, max_length=100)),
                ("industry", models.CharField(blank=True, max_length=100)),
                ("currency", models.CharField(default="CNY", max_length=10)),
                (
                    "total_shares",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Total shares outstanding",
                        max_digits=24,
                        null=True,
                    ),
                ),
                (
                    "extra",
                    models.JSONField(
                        blank=True, default=dict, help_text="Provider-specific extras"
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
            ],
            options={
                "verbose_name": "Asset",
                "verbose_name_plural": "Assets",
                "db_table": "data_center_asset_master",
                "ordering": ["code"],
                "indexes": [
                    models.Index(
                        fields=["asset_type", "exchange"], name="data_center_asset_t_858efe_idx"
                    ),
                    models.Index(fields=["is_active"], name="data_center_is_acti_59a408_idx"),
                ],
            },
        ),
        migrations.CreateModel(
            name="CapitalFlowFactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("asset_code", models.CharField(db_index=True, max_length=20)),
                ("flow_date", models.DateField(db_index=True)),
                (
                    "main_net",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Main-force net inflow (CNY)",
                        max_digits=24,
                        null=True,
                    ),
                ),
                (
                    "retail_net",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Retail net inflow (CNY)",
                        max_digits=24,
                        null=True,
                    ),
                ),
                (
                    "super_large_net",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=24, null=True),
                ),
                (
                    "large_net",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=24, null=True),
                ),
                (
                    "medium_net",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=24, null=True),
                ),
                (
                    "small_net",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=24, null=True),
                ),
                ("source", models.CharField(max_length=50)),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
                ("extra", models.JSONField(blank=True, default=dict)),
            ],
            options={
                "verbose_name": "Capital Flow Fact",
                "verbose_name_plural": "Capital Flow Facts",
                "db_table": "data_center_capital_flow_fact",
                "ordering": ["-flow_date"],
                "indexes": [
                    models.Index(
                        fields=["asset_code", "flow_date"], name="data_center_asset_c_e88bd9_idx"
                    )
                ],
                "unique_together": {("asset_code", "flow_date", "source")},
            },
        ),
        migrations.CreateModel(
            name="FinancialFactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("asset_code", models.CharField(db_index=True, max_length=20)),
                (
                    "period_end",
                    models.DateField(db_index=True, help_text="Period end date (e.g. 2024-12-31)"),
                ),
                (
                    "period_type",
                    models.CharField(
                        choices=[
                            ("annual", "Annual"),
                            ("semi_annual", "Semi-Annual"),
                            ("quarterly", "Quarterly"),
                            ("ttm", "TTM"),
                        ],
                        max_length=15,
                    ),
                ),
                (
                    "metric_code",
                    models.CharField(
                        db_index=True,
                        help_text="Metric identifier (e.g. revenue, net_profit, total_assets)",
                        max_length=60,
                    ),
                ),
                ("value", models.DecimalField(decimal_places=4, max_digits=28)),
                ("unit", models.CharField(blank=True, max_length=20)),
                ("source", models.CharField(max_length=50)),
                (
                    "report_date",
                    models.DateField(blank=True, help_text="Date report was published", null=True),
                ),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
                ("extra", models.JSONField(blank=True, default=dict)),
            ],
            options={
                "verbose_name": "Financial Fact",
                "verbose_name_plural": "Financial Facts",
                "db_table": "data_center_financial_fact",
                "ordering": ["-period_end"],
                "indexes": [
                    models.Index(
                        fields=["asset_code", "period_end"], name="data_center_asset_c_cc9d10_idx"
                    ),
                    models.Index(fields=["metric_code"], name="data_center_metric__a999a0_idx"),
                ],
                "unique_together": {
                    ("asset_code", "period_end", "period_type", "metric_code", "source")
                },
            },
        ),
        migrations.CreateModel(
            name="FundNavFactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("fund_code", models.CharField(db_index=True, max_length=20)),
                ("nav_date", models.DateField(db_index=True)),
                ("nav", models.DecimalField(decimal_places=6, help_text="Unit NAV", max_digits=18)),
                (
                    "acc_nav",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="Accumulated NAV",
                        max_digits=18,
                        null=True,
                    ),
                ),
                (
                    "daily_return",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="Daily return rate",
                        max_digits=10,
                        null=True,
                    ),
                ),
                ("source", models.CharField(max_length=50)),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
                ("extra", models.JSONField(blank=True, default=dict)),
            ],
            options={
                "verbose_name": "Fund NAV Fact",
                "verbose_name_plural": "Fund NAV Facts",
                "db_table": "data_center_fund_nav_fact",
                "ordering": ["-nav_date"],
                "indexes": [
                    models.Index(
                        fields=["fund_code", "nav_date"], name="data_center_fund_co_c51df9_idx"
                    )
                ],
                "unique_together": {("fund_code", "nav_date", "source")},
            },
        ),
        migrations.CreateModel(
            name="MacroFactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "indicator_code",
                    models.CharField(
                        db_index=True, help_text="Matches IndicatorCatalogModel.code", max_length=50
                    ),
                ),
                ("reporting_period", models.DateField(db_index=True)),
                ("value", models.DecimalField(decimal_places=6, max_digits=28)),
                ("unit", models.CharField(blank=True, max_length=20)),
                ("source", models.CharField(help_text="Provider name", max_length=50)),
                ("revision_number", models.SmallIntegerField(default=0)),
                ("published_at", models.DateField(blank=True, null=True)),
                (
                    "quality",
                    models.CharField(
                        choices=[
                            ("valid", "Valid"),
                            ("stale", "Stale"),
                            ("estimated", "Estimated"),
                            ("error", "Error"),
                            ("missing", "Missing"),
                        ],
                        default="valid",
                        max_length=10,
                    ),
                ),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
                ("extra", models.JSONField(blank=True, default=dict)),
            ],
            options={
                "verbose_name": "Macro Fact",
                "verbose_name_plural": "Macro Facts",
                "db_table": "data_center_macro_fact",
                "ordering": ["-reporting_period"],
                "indexes": [
                    models.Index(
                        fields=["indicator_code", "reporting_period"],
                        name="data_center_indicat_3889db_idx",
                    ),
                    models.Index(
                        fields=["source", "reporting_period"], name="data_center_source_80a73e_idx"
                    ),
                ],
                "unique_together": {
                    ("indicator_code", "reporting_period", "source", "revision_number")
                },
            },
        ),
        migrations.CreateModel(
            name="NewsFactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "asset_code",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="Primary associated ticker (blank = market-wide news)",
                        max_length=20,
                    ),
                ),
                ("title", models.CharField(max_length=500)),
                ("summary", models.TextField(blank=True)),
                ("url", models.URLField(blank=True, max_length=1000)),
                ("published_at", models.DateTimeField(db_index=True)),
                ("source", models.CharField(max_length=50)),
                (
                    "external_id",
                    models.CharField(blank=True, help_text="Provider article ID", max_length=200),
                ),
                (
                    "sentiment_score",
                    models.FloatField(
                        blank=True, help_text="Sentiment score in [-1, +1]", null=True
                    ),
                ),
                ("extra", models.JSONField(blank=True, default=dict)),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "News Article",
                "verbose_name_plural": "News Articles",
                "db_table": "data_center_news_fact",
                "ordering": ["-published_at"],
                "indexes": [
                    models.Index(
                        fields=["asset_code", "published_at"], name="data_center_asset_c_ba2466_idx"
                    ),
                    models.Index(fields=["published_at"], name="data_center_publish_3b5cc7_idx"),
                ],
                "unique_together": {("source", "external_id")},
            },
        ),
        migrations.CreateModel(
            name="PriceBarModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("asset_code", models.CharField(db_index=True, max_length=20)),
                ("bar_date", models.DateField(db_index=True)),
                (
                    "freq",
                    models.CharField(
                        choices=[
                            ("1d", "日线"),
                            ("1w", "周线"),
                            ("1mo", "月线"),
                            ("60m", "60分钟"),
                            ("30m", "30分钟"),
                            ("15m", "15分钟"),
                            ("5m", "5分钟"),
                            ("1m", "1分钟"),
                        ],
                        default="1d",
                        max_length=5,
                    ),
                ),
                (
                    "adjustment",
                    models.CharField(
                        choices=[("none", "不复权"), ("forward", "前复权"), ("backward", "后复权")],
                        default="none",
                        max_length=10,
                    ),
                ),
                ("open", models.DecimalField(decimal_places=4, max_digits=18)),
                ("high", models.DecimalField(decimal_places=4, max_digits=18)),
                ("low", models.DecimalField(decimal_places=4, max_digits=18)),
                ("close", models.DecimalField(decimal_places=4, max_digits=18)),
                (
                    "volume",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Volume in shares",
                        max_digits=24,
                        null=True,
                    ),
                ),
                (
                    "amount",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Turnover amount in CNY",
                        max_digits=24,
                        null=True,
                    ),
                ),
                ("source", models.CharField(max_length=50)),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "Price Bar",
                "verbose_name_plural": "Price Bars",
                "db_table": "data_center_price_bar",
                "ordering": ["-bar_date"],
                "indexes": [
                    models.Index(
                        fields=["asset_code", "bar_date"], name="data_center_asset_c_b604f7_idx"
                    )
                ],
                "unique_together": {("asset_code", "bar_date", "freq", "adjustment", "source")},
            },
        ),
        migrations.CreateModel(
            name="QuoteSnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("asset_code", models.CharField(db_index=True, max_length=20)),
                ("snapshot_at", models.DateTimeField(db_index=True)),
                ("current_price", models.DecimalField(decimal_places=4, max_digits=18)),
                (
                    "open",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                (
                    "high",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                (
                    "low",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                (
                    "prev_close",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                (
                    "volume",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=24, null=True),
                ),
                (
                    "amount",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=24, null=True),
                ),
                (
                    "bid",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                (
                    "ask",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                ("source", models.CharField(max_length=50)),
                ("extra", models.JSONField(blank=True, default=dict)),
            ],
            options={
                "verbose_name": "Quote Snapshot",
                "verbose_name_plural": "Quote Snapshots",
                "db_table": "data_center_quote_snapshot",
                "ordering": ["-snapshot_at"],
                "indexes": [
                    models.Index(
                        fields=["asset_code", "snapshot_at"], name="data_center_asset_c_32089c_idx"
                    )
                ],
                "unique_together": {("asset_code", "snapshot_at", "source")},
            },
        ),
        migrations.CreateModel(
            name="RawAuditModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("provider_name", models.CharField(db_index=True, max_length=50)),
                (
                    "capability",
                    models.CharField(
                        db_index=True,
                        help_text="DataCapability value (e.g. 'macro', 'historical_price')",
                        max_length=30,
                    ),
                ),
                ("request_params", models.JSONField(blank=True, default=dict)),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("ok", "OK"),
                            ("error", "Error"),
                            ("timeout", "Timeout"),
                            ("skipped", "Skipped"),
                        ],
                        max_length=10,
                    ),
                ),
                ("row_count", models.IntegerField(default=0, help_text="Number of rows fetched")),
                ("latency_ms", models.FloatField(blank=True, null=True)),
                ("error_message", models.TextField(blank=True)),
                ("fetched_at", models.DateTimeField(db_index=True)),
                ("extra", models.JSONField(blank=True, default=dict)),
            ],
            options={
                "verbose_name": "Raw Audit Log",
                "verbose_name_plural": "Raw Audit Logs",
                "db_table": "data_center_raw_audit",
                "ordering": ["-fetched_at"],
                "indexes": [
                    models.Index(
                        fields=["provider_name", "fetched_at"],
                        name="data_center_provide_f56841_idx",
                    ),
                    models.Index(
                        fields=["capability", "fetched_at"], name="data_center_capabil_99bc8e_idx"
                    ),
                ],
            },
        ),
        migrations.CreateModel(
            name="SectorMembershipFactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("asset_code", models.CharField(db_index=True, max_length=20)),
                (
                    "sector_code",
                    models.CharField(
                        db_index=True,
                        help_text="Industry / index code (e.g. 399300.SZ for CSI 300)",
                        max_length=30,
                    ),
                ),
                ("sector_name", models.CharField(blank=True, max_length=100)),
                ("effective_date", models.DateField()),
                (
                    "expiry_date",
                    models.DateField(blank=True, help_text="Null = currently active", null=True),
                ),
                (
                    "weight",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="Weight in index (0–1)",
                        max_digits=10,
                        null=True,
                    ),
                ),
                ("source", models.CharField(max_length=50)),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
            ],
            options={
                "verbose_name": "Sector Membership",
                "verbose_name_plural": "Sector Memberships",
                "db_table": "data_center_sector_membership",
                "ordering": ["-effective_date"],
                "indexes": [
                    models.Index(
                        fields=["sector_code", "effective_date"],
                        name="data_center_sector__09ec76_idx",
                    ),
                    models.Index(
                        fields=["asset_code", "effective_date"],
                        name="data_center_asset_c_1e2c2a_idx",
                    ),
                ],
                "unique_together": {("asset_code", "sector_code", "effective_date")},
            },
        ),
        migrations.CreateModel(
            name="ValuationFactModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("asset_code", models.CharField(db_index=True, max_length=20)),
                ("val_date", models.DateField(db_index=True)),
                (
                    "pe_ttm",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                (
                    "pe_static",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                ("pb", models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True)),
                (
                    "ps_ttm",
                    models.DecimalField(blank=True, decimal_places=4, max_digits=18, null=True),
                ),
                (
                    "market_cap",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="Market cap in CNY",
                        max_digits=28,
                        null=True,
                    ),
                ),
                (
                    "float_market_cap",
                    models.DecimalField(blank=True, decimal_places=2, max_digits=28, null=True),
                ),
                (
                    "dv_ratio",
                    models.DecimalField(
                        blank=True,
                        decimal_places=6,
                        help_text="Dividend yield",
                        max_digits=10,
                        null=True,
                    ),
                ),
                ("source", models.CharField(max_length=50)),
                ("fetched_at", models.DateTimeField(auto_now_add=True)),
                ("extra", models.JSONField(blank=True, default=dict)),
            ],
            options={
                "verbose_name": "Valuation Fact",
                "verbose_name_plural": "Valuation Facts",
                "db_table": "data_center_valuation_fact",
                "ordering": ["-val_date"],
                "indexes": [
                    models.Index(
                        fields=["asset_code", "val_date"], name="data_center_asset_c_7ffd94_idx"
                    )
                ],
                "unique_together": {("asset_code", "val_date", "source")},
            },
        ),
        migrations.CreateModel(
            name="AssetAliasModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "provider_name",
                    models.CharField(
                        help_text="Provider identifier (e.g. 'akshare', 'wind')", max_length=50
                    ),
                ),
                (
                    "alias_code",
                    models.CharField(help_text="Provider-local ticker code", max_length=40),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                (
                    "asset",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="aliases",
                        to="data_center.assetmastermodel",
                    ),
                ),
            ],
            options={
                "db_table": "data_center_asset_alias",
                "indexes": [
                    models.Index(fields=["alias_code"], name="data_center_alias_c_8a77e0_idx")
                ],
                "unique_together": {("provider_name", "alias_code")},
            },
        ),
    ]
