feat(weibo): 增加账号分配与客服数据隔离

This commit is contained in:
yml2213
2026-11-08 18:30:51 +08:00
parent c8b62e5267
commit 6b2285913f
16 changed files with 1320 additions and 55 deletions
@@ -0,0 +1,59 @@
"""增加微博账号归属客服。"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "20261108_0074"
down_revision: str | None = "20261108_0073"
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_accounts"):
return
columns = {column["name"] for column in inspector.get_columns("weibo_accounts")}
if "assigned_to" not in columns:
op.add_column(
"weibo_accounts",
sa.Column("assigned_to", sa.Integer(), nullable=True),
)
op.create_foreign_key(
"fk_weibo_accounts_assigned_to_users",
"weibo_accounts",
"users",
["assigned_to"],
["id"],
ondelete="SET NULL",
)
indexes = {index["name"] for index in inspector.get_indexes("weibo_accounts")}
if "ix_weibo_accounts_assigned_to" not in indexes:
op.create_index(
"ix_weibo_accounts_assigned_to",
"weibo_accounts",
["assigned_to"],
)
def downgrade() -> None:
inspector = sa.inspect(op.get_bind())
if not inspector.has_table("weibo_accounts"):
return
foreign_keys = {fk["name"] for fk in inspector.get_foreign_keys("weibo_accounts")}
if "fk_weibo_accounts_assigned_to_users" in foreign_keys:
op.drop_constraint(
"fk_weibo_accounts_assigned_to_users",
"weibo_accounts",
type_="foreignkey",
)
indexes = {index["name"] for index in inspector.get_indexes("weibo_accounts")}
if "ix_weibo_accounts_assigned_to" in indexes:
op.drop_index("ix_weibo_accounts_assigned_to", table_name="weibo_accounts")
columns = {column["name"] for column in inspector.get_columns("weibo_accounts")}
if "assigned_to" in columns:
op.drop_column("weibo_accounts", "assigned_to")