# Generated by Django 5.2.10 on 2026-03-04 15:54

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


class Migration(migrations.Migration):

    dependencies = [
        ("account", "0014_portfolioobservergrantmodel"),
        ("strategy", "0004_positionmanagementrulemodel"),
    ]

    operations = [
        migrations.CreateModel(
            name="StrategyParamVersionModel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                ("version", models.PositiveIntegerField(db_index=True, verbose_name="版本号")),
                (
                    "params_json",
                    models.JSONField(help_text="策略参数的JSON序列化", verbose_name="参数配置"),
                ),
                (
                    "is_active",
                    models.BooleanField(
                        db_index=True,
                        default=False,
                        help_text="同一策略只能有一个激活版本",
                        verbose_name="是否激活",
                    ),
                ),
                (
                    "change_description",
                    models.TextField(
                        blank=True,
                        help_text="记录本次参数变更的原因和内容",
                        verbose_name="变更说明",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True, verbose_name="创建时间")),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
                (
                    "changed_by",
                    models.ForeignKey(
                        blank=True,
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="account.accountprofilemodel",
                        verbose_name="变更者",
                    ),
                ),
                (
                    "strategy",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="param_versions",
                        to="strategy.strategymodel",
                        verbose_name="所属策略",
                    ),
                ),
            ],
            options={
                "verbose_name": "策略参数版本",
                "verbose_name_plural": "策略参数版本",
                "db_table": "strategy_param_version",
                "ordering": ["-version"],
                "indexes": [
                    models.Index(
                        fields=["strategy", "-version"], name="strategy_pa_strateg_56edc0_idx"
                    ),
                    models.Index(
                        fields=["strategy", "is_active"], name="strategy_pa_strateg_35e935_idx"
                    ),
                    models.Index(fields=["-created_at"], name="strategy_pa_created_0724d9_idx"),
                ],
                "unique_together": {("strategy", "version")},
            },
        ),
    ]
