fix(douyu): 自动校验兑换资格并稳定账号导入顺序
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""保存斗鱼工作台账号的显式展示顺序。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261119_0097"
|
||||
down_revision: str | None = "20261118_0096"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
TABLE = "douyu_workbench_accounts"
|
||||
COLUMN = "sort_order"
|
||||
|
||||
|
||||
def _column_exists() -> bool:
|
||||
return bool(
|
||||
op.get_bind()
|
||||
.execute(
|
||||
sa.text(
|
||||
"SELECT COUNT(*) FROM information_schema.columns "
|
||||
"WHERE table_schema = DATABASE() "
|
||||
"AND table_name = :table AND column_name = :column"
|
||||
),
|
||||
{"table": TABLE, "column": COLUMN},
|
||||
)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _column_exists():
|
||||
op.add_column(
|
||||
TABLE,
|
||||
sa.Column(
|
||||
COLUMN,
|
||||
sa.Integer(),
|
||||
nullable=False,
|
||||
server_default="0",
|
||||
),
|
||||
)
|
||||
# 历史数据没有显式顺序,用原自增 ID 恢复当时的插入顺序。
|
||||
op.execute(f"UPDATE `{TABLE}` SET `{COLUMN}` = `id`")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _column_exists():
|
||||
op.drop_column(TABLE, COLUMN)
|
||||
Reference in New Issue
Block a user