feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -0,0 +1,67 @@
|
||||
"""移除已下线 APX 自动推进运行时。
|
||||
|
||||
用途:收口遗留 APX Execution/Job 并删除仅服务旧六门禁运行时的唯一索引。
|
||||
依赖:shipping_process_executions、shipping_process_gates、jobs。
|
||||
逻辑:正式 20-Gate 是唯一运行态;迁移只终止 APX 记录,绝不改写正式 Execution、STP、Excel 或 RPA Job。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = 'hm6n7o8p9q0r'
|
||||
down_revision = 'hk5l6m7n8o9p'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _indexes(table: str) -> set[str]:
|
||||
"""读取索引名,保证不同环境重复升级安全。"""
|
||||
return {str(item.get('name') or '') for item in sa.inspect(op.get_bind()).get_indexes(table)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""终态化 APX 旧运行记录,再删除旧类型唯一索引。"""
|
||||
bind = op.get_bind()
|
||||
bind.execute(sa.text("""
|
||||
UPDATE jobs
|
||||
SET status = 'cancelled', finished_at = COALESCE(finished_at, CURRENT_TIMESTAMP),
|
||||
message = 'legacy APX auto-progress runtime removed'
|
||||
WHERE domain = 'shipping_notice'
|
||||
AND job_type = 'shipping_auto_progress'
|
||||
AND status IN ('queued', 'running', 'active')
|
||||
"""))
|
||||
bind.execute(sa.text("""
|
||||
UPDATE shipping_process_gates
|
||||
SET status = 'cancelled', updated_at = CURRENT_TIMESTAMP
|
||||
WHERE execution_id IN (
|
||||
SELECT id FROM shipping_process_executions WHERE execution_no LIKE 'APX-%'
|
||||
)
|
||||
AND status IN ('pending', 'queued', 'running', 'blocked_retryable', 'blocked_manual', 'invalidated')
|
||||
"""))
|
||||
bind.execute(sa.text("""
|
||||
UPDATE shipping_process_executions
|
||||
SET status = 'superseded', updated_at = CURRENT_TIMESTAMP
|
||||
WHERE execution_no LIKE 'APX-%'
|
||||
AND status IN ('active', 'blocked', 'waiting_external')
|
||||
"""))
|
||||
if 'uq_jobs_shipping_auto_progress_one_active_task' in _indexes('jobs'):
|
||||
op.drop_index('uq_jobs_shipping_auto_progress_one_active_task', table_name='jobs')
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""仅恢复旧索引定义;已终态化的 APX 记录不应被自动复活。"""
|
||||
if 'uq_jobs_shipping_auto_progress_one_active_task' not in _indexes('jobs'):
|
||||
op.create_index(
|
||||
'uq_jobs_shipping_auto_progress_one_active_task', 'jobs', ['task_id'], unique=True,
|
||||
postgresql_where=sa.text(
|
||||
"domain = 'shipping_notice' AND job_type = 'shipping_auto_progress' "
|
||||
"AND status IN ('queued', 'running') AND task_id IS NOT NULL"
|
||||
),
|
||||
sqlite_where=sa.text(
|
||||
"domain = 'shipping_notice' AND job_type = 'shipping_auto_progress' "
|
||||
"AND status IN ('queued', 'running') AND task_id IS NOT NULL"
|
||||
),
|
||||
)
|
||||
Reference in new issue
Block a user