feat(weibo): 优化协作单详情并增加已上脚本状态
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""微博外部单协作增加上脚本时间,并回填已完成订单。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261112_0080"
|
||||
down_revision: str | None = "20261112_0079"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
TABLE = "weibo_external_orders"
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
if not inspector.has_table(TABLE):
|
||||
return
|
||||
columns = {column["name"] for column in inspector.get_columns(TABLE)}
|
||||
if "scripted_at" not in columns:
|
||||
op.add_column(TABLE, sa.Column("scripted_at", sa.DateTime(), nullable=True))
|
||||
bind.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
UPDATE {TABLE}
|
||||
SET scripted_at = COALESCE(scripted_at, exchange_started_at, done_at, updated_at)
|
||||
WHERE status IN ('scripted', 'done')
|
||||
AND scripted_at IS NULL
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
if not inspector.has_table(TABLE):
|
||||
return
|
||||
columns = {column["name"] for column in inspector.get_columns(TABLE)}
|
||||
if "scripted_at" in columns:
|
||||
op.drop_column(TABLE, "scripted_at")
|
||||
Reference in New Issue
Block a user