feat(weibo): 拆分账号管理与个人工作台

This commit is contained in:
yml2213
2026-11-08 16:26:53 +08:00
parent 5d6325d74c
commit d566518478
13 changed files with 1307 additions and 93 deletions
@@ -0,0 +1,64 @@
"""增加微博个人工作台账号映射。"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "20261108_0072"
down_revision: str | None = "20261108_0071"
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"):
op.create_table(
"weibo_workbench_accounts",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
sa.Column("user_id", sa.Integer(), nullable=False),
sa.Column("account_id", sa.Integer(), nullable=False),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(
["account_id"],
["weibo_accounts.id"],
ondelete="CASCADE",
),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
ondelete="CASCADE",
),
sa.UniqueConstraint(
"user_id",
"account_id",
name="uq_weibo_workbench_account",
),
)
inspector = sa.inspect(op.get_bind())
existing_indexes = {
index["name"] for index in inspector.get_indexes("weibo_workbench_accounts")
}
if "ix_weibo_workbench_accounts_user_id" not in existing_indexes:
op.create_index(
"ix_weibo_workbench_accounts_user_id",
"weibo_workbench_accounts",
["user_id"],
)
if "ix_weibo_workbench_accounts_account_id" not in existing_indexes:
op.create_index(
"ix_weibo_workbench_accounts_account_id",
"weibo_workbench_accounts",
["account_id"],
)
def downgrade() -> None:
inspector = sa.inspect(op.get_bind())
if not inspector.has_table("weibo_workbench_accounts"):
return
op.drop_table("weibo_workbench_accounts")