feat(weibo): 增加工作台独占与快捷操作

This commit is contained in:
yml2213
2026-11-08 16:39:32 +08:00
parent d566518478
commit c8b62e5267
10 changed files with 341 additions and 29 deletions
@@ -0,0 +1,54 @@
"""限制微博账号同时只能属于一个个人工作台。"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "20261108_0073"
down_revision: str | None = "20261108_0072"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
inspector = sa.inspect(op.get_bind())
if not inspector.has_table("weibo_workbench_accounts"):
return
# 历史若已有重复占用,保留最早加入的一条,其余释放。
op.execute(
sa.text(
"DELETE newer FROM weibo_workbench_accounts AS newer "
"JOIN weibo_workbench_accounts AS older "
"ON newer.account_id = older.account_id AND newer.id > older.id"
)
)
constraints = {
item["name"]
for item in inspector.get_unique_constraints("weibo_workbench_accounts")
}
if "uq_weibo_workbench_account_owner" not in constraints:
op.create_unique_constraint(
"uq_weibo_workbench_account_owner",
"weibo_workbench_accounts",
["account_id"],
)
def downgrade() -> None:
inspector = sa.inspect(op.get_bind())
if not inspector.has_table("weibo_workbench_accounts"):
return
constraints = {
item["name"]
for item in inspector.get_unique_constraints("weibo_workbench_accounts")
}
if "uq_weibo_workbench_account_owner" in constraints:
op.drop_constraint(
"uq_weibo_workbench_account_owner",
"weibo_workbench_accounts",
type_="unique",
)