"""直播账号履约保存 order_site 客户资料与主页截图。 客户领取页改为必填主页截图;order_site 通过 integration API 推送到 live-hub, 履约工作台直接展示并和绑定角色比对,不再由客服手动索要。 """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision: str = "20261124_0131" down_revision: str | None = "20261124_0130" branch_labels: str | None = None depends_on: str | None = None TABLE = "platform_fulfillment_tasks" COLUMNS = { "customer_role_name": sa.String(length=128), "customer_platform": sa.String(length=16), "customer_system": sa.String(length=16), "customer_home_images": sa.JSON(), "customer_profile_updated_at": sa.DateTime(), } def _column_exists(name: str) -> bool: conn = op.get_bind() count = conn.execute( sa.text( "SELECT COUNT(*) FROM information_schema.columns " "WHERE table_schema = DATABASE() AND table_name = :table " "AND column_name = :name" ), {"table": TABLE, "name": name}, ).scalar() return bool(count) def upgrade() -> None: text_columns = { "customer_role_name", "customer_platform", "customer_system", } for name, column_type in COLUMNS.items(): if _column_exists(name): continue op.add_column( TABLE, sa.Column( name, column_type, nullable=name not in text_columns, server_default="" if name in text_columns else None, ), ) def downgrade() -> None: for name in reversed(tuple(COLUMNS)): if _column_exists(name): op.drop_column(TABLE, name)