feat(fulfillment): 增加订单匹配起算时间
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
"""直播账号履约订单匹配起算时间
|
||||
|
||||
迁移上线即把起算时间设为当前时刻,避免历史人工订单在启用商品映射后被
|
||||
重新匹配。历史任务保留,但不进入工作台、自动选号和客户领取会话。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "20261118_0087"
|
||||
down_revision: str | None = "20261117_0086"
|
||||
branch_labels: str | None = None
|
||||
depends_on: str | None = None
|
||||
|
||||
|
||||
def _column_exists(table: str, column: str) -> bool:
|
||||
return bool(
|
||||
op.get_bind()
|
||||
.execute(
|
||||
sa.text(
|
||||
"SELECT COUNT(*) FROM information_schema.columns "
|
||||
"WHERE table_schema = DATABASE() "
|
||||
"AND table_name = :table AND column_name = :column"
|
||||
),
|
||||
{"table": table, "column": column},
|
||||
)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
if not _column_exists(
|
||||
"platform_fulfillment_settings",
|
||||
"order_match_started_at",
|
||||
):
|
||||
op.add_column(
|
||||
"platform_fulfillment_settings",
|
||||
sa.Column("order_match_started_at", sa.DateTime(), nullable=True),
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE platform_fulfillment_settings
|
||||
SET order_match_started_at = NOW()
|
||||
WHERE order_match_started_at IS NULL
|
||||
"""
|
||||
)
|
||||
)
|
||||
op.alter_column(
|
||||
"platform_fulfillment_settings",
|
||||
"order_match_started_at",
|
||||
existing_type=sa.DateTime(),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _column_exists(
|
||||
"platform_fulfillment_settings",
|
||||
"order_match_started_at",
|
||||
):
|
||||
op.drop_column(
|
||||
"platform_fulfillment_settings",
|
||||
"order_match_started_at",
|
||||
)
|
||||
Reference in New Issue
Block a user