功能: 按用户同步斗鱼工作台
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
"""持久化斗鱼工作台账号归属和任务手册范围
|
||||
|
||||
Revision ID: 20260813_0024
|
||||
Revises: 20260813_0023
|
||||
Create Date: 2026-08-13
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "20260813_0024"
|
||||
down_revision: Union[str, None] = "20260813_0023"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def _columns(bind, table_name: str) -> set[str]:
|
||||
return {column["name"] for column in sa.inspect(bind).get_columns(table_name)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if "handbook_scope" not in _columns(bind, "douyu_tasks"):
|
||||
op.add_column(
|
||||
"douyu_tasks",
|
||||
sa.Column("handbook_scope", sa.String(length=16), nullable=False, server_default="legacy"),
|
||||
)
|
||||
op.create_index("ix_douyu_tasks_handbook_scope", "douyu_tasks", ["handbook_scope"])
|
||||
|
||||
if not sa.inspect(bind).has_table("douyu_workbench_accounts"):
|
||||
op.create_table(
|
||||
"douyu_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("handbook_scope", sa.String(length=16), nullable=False),
|
||||
sa.Column("account_id", sa.Integer(), sa.ForeignKey("accounts.id"), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(), nullable=True),
|
||||
sa.UniqueConstraint("user_id", "handbook_scope", "account_id", name="uq_douyu_workbench_account"),
|
||||
)
|
||||
op.create_index("ix_douyu_workbench_accounts_user_id", "douyu_workbench_accounts", ["user_id"])
|
||||
op.create_index("ix_douyu_workbench_accounts_handbook_scope", "douyu_workbench_accounts", ["handbook_scope"])
|
||||
op.create_index("ix_douyu_workbench_accounts_account_id", "douyu_workbench_accounts", ["account_id"])
|
||||
|
||||
if not sa.inspect(bind).has_table("douyu_workbenches"):
|
||||
op.create_table(
|
||||
"douyu_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("handbook_scope", sa.String(length=16), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
||||
sa.UniqueConstraint("user_id", "handbook_scope", name="uq_douyu_workbench"),
|
||||
)
|
||||
op.create_index("ix_douyu_workbenches_user_id", "douyu_workbenches", ["user_id"])
|
||||
op.create_index("ix_douyu_workbenches_handbook_scope", "douyu_workbenches", ["handbook_scope"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if sa.inspect(bind).has_table("douyu_workbenches"):
|
||||
op.drop_table("douyu_workbenches")
|
||||
if sa.inspect(bind).has_table("douyu_workbench_accounts"):
|
||||
op.drop_table("douyu_workbench_accounts")
|
||||
if "handbook_scope" in _columns(bind, "douyu_tasks"):
|
||||
op.drop_index("ix_douyu_tasks_handbook_scope", table_name="douyu_tasks")
|
||||
op.drop_column("douyu_tasks", "handbook_scope")
|
||||
@@ -0,0 +1,39 @@
|
||||
"""补齐工作台空状态同步表
|
||||
|
||||
Revision ID: 20260813_0025
|
||||
Revises: 20260813_0024
|
||||
Create Date: 2026-08-13
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = "20260813_0025"
|
||||
down_revision: Union[str, None] = "20260813_0024"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if sa.inspect(bind).has_table("douyu_workbenches"):
|
||||
return
|
||||
op.create_table(
|
||||
"douyu_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("handbook_scope", sa.String(length=16), nullable=False),
|
||||
sa.Column("updated_at", sa.DateTime(), nullable=True),
|
||||
sa.UniqueConstraint("user_id", "handbook_scope", name="uq_douyu_workbench"),
|
||||
)
|
||||
op.create_index("ix_douyu_workbenches_user_id", "douyu_workbenches", ["user_id"])
|
||||
op.create_index("ix_douyu_workbenches_handbook_scope", "douyu_workbenches", ["handbook_scope"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
if sa.inspect(bind).has_table("douyu_workbenches"):
|
||||
op.drop_table("douyu_workbenches")
|
||||
Reference in New Issue
Block a user