# Generated by Django 5.2.9 on 2025-12-31 05:19

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


class Migration(migrations.Migration):

    dependencies = [
        ("account", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="PortfolioDailySnapshotModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("snapshot_date", models.DateField(db_index=True, verbose_name="快照日期")),
                (
                    "total_value",
                    models.DecimalField(decimal_places=2, max_digits=20, verbose_name="总资产"),
                ),
                (
                    "cash_balance",
                    models.DecimalField(
                        decimal_places=2, default=0, max_digits=20, verbose_name="现金余额"
                    ),
                ),
                (
                    "invested_value",
                    models.DecimalField(
                        decimal_places=2, default=0, max_digits=20, verbose_name="投资市值"
                    ),
                ),
                ("position_count", models.IntegerField(default=0, verbose_name="持仓数量")),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
            ],
            options={
                "verbose_name": "投资组合日快照",
                "verbose_name_plural": "投资组合日快照",
                "db_table": "portfolio_daily_snapshot",
                "ordering": ["-snapshot_date"],
            },
        ),
        migrations.RenameIndex(
            model_name="assetmetadatamodel",
            new_name="asset_metad_asset_c_2a3e6a_idx",
            old_name="account_a_asset__code_idx",
        ),
        migrations.RenameIndex(
            model_name="assetmetadatamodel",
            new_name="asset_metad_asset_c_e1c9fd_idx",
            old_name="account_a_asset__class_idx",
        ),
        migrations.RenameIndex(
            model_name="positionmodel",
            new_name="position_portfol_5ce992_idx",
            old_name="account_p_portfoli__asset__code_idx",
        ),
        migrations.RenameIndex(
            model_name="positionmodel",
            new_name="position_source_8d15d4_idx",
            old_name="account_p_source__source__id_idx",
        ),
        migrations.RenameIndex(
            model_name="positionmodel",
            new_name="position_asset_c_09cb42_idx",
            old_name="account_p_asset__class__region_idx",
        ),
        migrations.RenameIndex(
            model_name="positionmodel",
            new_name="position_is_clos_81dde3_idx",
            old_name="account_p_is_closed_idx",
        ),
        migrations.RenameIndex(
            model_name="transactionmodel",
            new_name="transaction_portfol_765c2b_idx",
            old_name="account_t_portfolio__traded__at_idx",
        ),
        migrations.RenameIndex(
            model_name="transactionmodel",
            new_name="transaction_asset_c_eff443_idx",
            old_name="account_t_asset_code_idx",
        ),
        migrations.AlterField(
            model_name="assetmetadatamodel",
            name="created_at",
            field=models.DateTimeField(auto_now_add=True),
        ),
        migrations.AlterField(
            model_name="assetmetadatamodel",
            name="updated_at",
            field=models.DateTimeField(auto_now=True),
        ),
        migrations.AddField(
            model_name="portfoliodailysnapshotmodel",
            name="portfolio",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="daily_snapshots",
                to="account.portfoliomodel",
                verbose_name="投资组合",
            ),
        ),
        migrations.AddIndex(
            model_name="portfoliodailysnapshotmodel",
            index=models.Index(
                fields=["portfolio", "-snapshot_date"], name="portfolio_d_portfol_a2266a_idx"
            ),
        ),
        migrations.AlterUniqueTogether(
            name="portfoliodailysnapshotmodel",
            unique_together={("portfolio", "snapshot_date")},
        ),
    ]
