51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
"""将斗鱼供应商直充默认账号模板切换为昵称。
|
|
|
|
Revision ID: 20260814_0028
|
|
Revises: 20260813_0027
|
|
Create Date: 2026-08-14
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "20260814_0028"
|
|
down_revision: str | None = "20260813_0027"
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""只迁移历史默认值,保留运营人员明确配置的模板名。"""
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
if not inspector.has_table("douyu_config"):
|
|
return
|
|
columns = {column["name"] for column in inspector.get_columns("douyu_config")}
|
|
if "gold_api_account_template_name" in columns:
|
|
op.execute(
|
|
sa.text(
|
|
"UPDATE douyu_config SET gold_api_account_template_name = :new "
|
|
"WHERE gold_api_account_template_name IS NULL "
|
|
"OR TRIM(gold_api_account_template_name) = '' "
|
|
"OR gold_api_account_template_name = :old"
|
|
).bindparams(new="斗鱼昵称", old="斗鱼UID")
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""回滚时只回退本迁移设置的默认昵称。"""
|
|
bind = op.get_bind()
|
|
inspector = sa.inspect(bind)
|
|
if not inspector.has_table("douyu_config"):
|
|
return
|
|
columns = {column["name"] for column in inspector.get_columns("douyu_config")}
|
|
if "gold_api_account_template_name" in columns:
|
|
op.execute(
|
|
sa.text(
|
|
"UPDATE douyu_config SET gold_api_account_template_name = :old "
|
|
"WHERE gold_api_account_template_name = :new"
|
|
).bindparams(new="斗鱼昵称", old="斗鱼UID")
|
|
)
|