feat: update strategy set schema fields

This commit is contained in:
2026-04-03 08:03:27 +00:00
parent 3eae90a9ab
commit ebd4559939
13 changed files with 131 additions and 37 deletions
@@ -0,0 +1,73 @@
"""rename strategy_set columns and add nick
Revision ID: 20260403_0002
Revises: 20260403_0001
Create Date: 2026-04-03 00:30:00
"""
from __future__ import annotations
from alembic import op
import sqlalchemy as sa
revision = "20260403_0002"
down_revision = "20260403_0001"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column("strategy_sets", sa.Column("name", sa.Text(), nullable=True))
op.add_column("strategy_sets", sa.Column("config", sa.Text(), nullable=True, server_default=""))
op.add_column("strategy_sets", sa.Column("nick", sa.Text(), nullable=True))
op.execute(
sa.text(
"""
UPDATE strategy_sets
SET
name = strategy_name,
config = strategy_config,
nick = strategy_name || ':' || substr(md5(strategy_config), 1, 12)
"""
)
)
op.alter_column("strategy_sets", "name", nullable=False)
op.alter_column("strategy_sets", "config", nullable=False)
op.alter_column("strategy_sets", "nick", nullable=False)
op.drop_constraint("uq_strategy_sets_name_config", "strategy_sets", type_="unique")
op.create_unique_constraint("uq_strategy_sets_name_config", "strategy_sets", ["name", "config"])
op.create_unique_constraint("uq_strategy_sets_nick", "strategy_sets", ["nick"])
op.drop_column("strategy_sets", "strategy_name")
op.drop_column("strategy_sets", "strategy_config")
def downgrade() -> None:
op.add_column("strategy_sets", sa.Column("strategy_name", sa.Text(), nullable=True))
op.add_column("strategy_sets", sa.Column("strategy_config", sa.Text(), nullable=True, server_default=""))
op.execute(
sa.text(
"""
UPDATE strategy_sets
SET
strategy_name = name,
strategy_config = config
"""
)
)
op.alter_column("strategy_sets", "strategy_name", nullable=False)
op.alter_column("strategy_sets", "strategy_config", nullable=False)
op.drop_constraint("uq_strategy_sets_nick", "strategy_sets", type_="unique")
op.drop_constraint("uq_strategy_sets_name_config", "strategy_sets", type_="unique")
op.create_unique_constraint("uq_strategy_sets_name_config", "strategy_sets", ["strategy_name", "strategy_config"])
op.drop_column("strategy_sets", "nick")
op.drop_column("strategy_sets", "name")
op.drop_column("strategy_sets", "config")