统一推送前Python代码格式

This commit is contained in:
yml2213
2026-09-05 19:25:46 +08:00
parent 90a0065918
commit 8309072120
17 changed files with 492 additions and 189 deletions
@@ -20,36 +20,69 @@ def upgrade() -> None:
if "handbook_scope" not in _columns(bind, "huya_tasks"):
op.add_column(
"huya_tasks",
sa.Column("handbook_scope", sa.String(length=16), nullable=False, server_default="legacy"),
sa.Column(
"handbook_scope",
sa.String(length=16),
nullable=False,
server_default="legacy",
),
)
op.create_index(
"ix_huya_tasks_handbook_scope", "huya_tasks", ["handbook_scope"]
)
op.create_index("ix_huya_tasks_handbook_scope", "huya_tasks", ["handbook_scope"])
inspector = sa.inspect(bind)
if not inspector.has_table("huya_workbench_accounts"):
op.create_table(
"huya_workbench_accounts",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("user_id", sa.Integer(), sa.ForeignKey("users.id"), nullable=False),
sa.Column(
"user_id", sa.Integer(), sa.ForeignKey("users.id"), nullable=False
),
sa.Column("handbook_scope", sa.String(length=16), nullable=False),
sa.Column("account_id", sa.Integer(), sa.ForeignKey("huya_accounts.id"), nullable=False),
sa.Column(
"account_id",
sa.Integer(),
sa.ForeignKey("huya_accounts.id"),
nullable=False,
),
sa.Column("created_at", sa.DateTime(), nullable=True),
sa.UniqueConstraint("user_id", "handbook_scope", "account_id", name="uq_huya_workbench_account"),
sa.UniqueConstraint(
"user_id",
"handbook_scope",
"account_id",
name="uq_huya_workbench_account",
),
)
op.create_index(
"ix_huya_workbench_accounts_user_id", "huya_workbench_accounts", ["user_id"]
)
op.create_index(
"ix_huya_workbench_accounts_handbook_scope",
"huya_workbench_accounts",
["handbook_scope"],
)
op.create_index(
"ix_huya_workbench_accounts_account_id",
"huya_workbench_accounts",
["account_id"],
)
op.create_index("ix_huya_workbench_accounts_user_id", "huya_workbench_accounts", ["user_id"])
op.create_index("ix_huya_workbench_accounts_handbook_scope", "huya_workbench_accounts", ["handbook_scope"])
op.create_index("ix_huya_workbench_accounts_account_id", "huya_workbench_accounts", ["account_id"])
if not inspector.has_table("huya_workbenches"):
op.create_table(
"huya_workbenches",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("user_id", sa.Integer(), sa.ForeignKey("users.id"), nullable=False),
sa.Column(
"user_id", sa.Integer(), sa.ForeignKey("users.id"), nullable=False
),
sa.Column("handbook_scope", sa.String(length=16), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=True),
sa.UniqueConstraint("user_id", "handbook_scope", name="uq_huya_workbench"),
)
op.create_index("ix_huya_workbenches_user_id", "huya_workbenches", ["user_id"])
op.create_index("ix_huya_workbenches_handbook_scope", "huya_workbenches", ["handbook_scope"])
op.create_index(
"ix_huya_workbenches_handbook_scope", "huya_workbenches", ["handbook_scope"]
)
def downgrade() -> None:
@@ -19,9 +19,7 @@ depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
bind = op.get_bind()
columns = {
item["name"] for item in sa.inspect(bind).get_columns("huya_accounts")
}
columns = {item["name"] for item in sa.inspect(bind).get_columns("huya_accounts")}
if "raw_cookie" not in columns:
# MySQL 的 TEXT 列不允许 server_default;模型层 default="" 负责新行,
# 存量行为 NULL(读取处按空处理)。
@@ -33,8 +31,6 @@ def upgrade() -> None:
def downgrade() -> None:
bind = op.get_bind()
columns = {
item["name"] for item in sa.inspect(bind).get_columns("huya_accounts")
}
columns = {item["name"] for item in sa.inspect(bind).get_columns("huya_accounts")}
if "raw_cookie" in columns:
op.drop_column("huya_accounts", "raw_cookie")
op.drop_column("huya_accounts", "raw_cookie")