Files
qlib/backend/app/infrastructure/persistence/migrations/versions/e1f2a3b4c5d6_strategy_table.py
T
Simon 9d25d466e5 feat(strategy): M8.3 策略模型 + /api/strategies(命名配置资产,可展开为 ResearchSpec)
- StrategyDefinition:universe/factors/selection/rebalance/costs/portfolio +
  price_adjustment(除 period 外完整策略定义);to_research_spec(period) 展开为标准 Spec
- strategy 表(migration e1f2a3b4c5d6,MySQL 已应用;name 唯一)+ StrategyRepository
- /api/strategies:POST/GET/DELETE + POST /{id}/expand(period+initial_capital → ResearchSpec)
- tests/test_strategies.py(repo CRUD/同名/expand、API CRUD/400/404);全量 pytest 通过
2026-09-09 00:38:09 +08:00

39 lines
1.1 KiB
Python

"""strategy 表(M8.3 策略持久化)
Revision ID: e1f2a3b4c5d6
Revises: d8e0b2f3c4d5
Create Date: 2026-09-09
"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "e1f2a3b4c5d6"
down_revision: str | None = "d8e0b2f3c4d5"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.create_table(
"strategy",
sa.Column("id", sa.String(length=32), nullable=False),
sa.Column("name", sa.String(length=64), nullable=False),
sa.Column("description", sa.String(length=300), nullable=False),
sa.Column("spec_type", sa.String(length=16), nullable=False),
sa.Column("config_json", sa.Text(), nullable=False),
sa.Column("version", sa.String(length=16), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("name", name="uq_strategy_name"),
)
def downgrade() -> None:
op.drop_table("strategy")