refactor(agent, shipping): 简化代理模型并完善订单抽取业务
- 移除 Agent 的 exposure_mode 与 internal_executor 相关逻辑,清理关联的过滤、序列化代码 - 删除废弃的 AgentRuntimeBinding 模型及其依赖 - 新增订单抽取上传批次、请求快照等数据库迁移与业务逻辑 - 修复附件完整性检测、订单抽取状态映射问题 - 更新多语言错误文案与前端单元测试配置 - 清理平台配置中不再使用的暴露模式配置
This commit is contained in:
1 parent
1f3ecb87b7
commit
61ac6403c4
159 files changed
+12883
-5099
No files matched your search
@@ -0,0 +1,228 @@
|
||||
"""rebuild order extraction progress facts
|
||||
|
||||
Revision ID: 0ab45c6d7e8f
|
||||
Revises: 09a23b4c5d6e
|
||||
Create Date: 2026-07-28 15:30:00.000000
|
||||
|
||||
用途:重建订单解析 Run/Unit/Event 的确定性业务进度事实模型。
|
||||
依赖:shipping_order_extraction_runs、shipping_order_extraction_units、shipping_order_extraction_progress_events。
|
||||
逻辑:不做旧 Workflow 字段兼容,直接替换为 Run 汇总与 Unit 业务事件结构。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '0ab45c6d7e8f'
|
||||
down_revision = '09a23b4c5d6e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _columns(inspector: sa.Inspector, table_name: str) -> set[str]:
|
||||
return {column['name'] for column in inspector.get_columns(table_name)}
|
||||
|
||||
|
||||
def _indexes(inspector: sa.Inspector, table_name: str) -> set[str]:
|
||||
return {index['name'] for index in inspector.get_indexes(table_name)}
|
||||
|
||||
|
||||
def _has_table(inspector: sa.Inspector, table_name: str) -> bool:
|
||||
return table_name in inspector.get_table_names()
|
||||
|
||||
|
||||
def _check_constraints(inspector: sa.Inspector, table_name: str) -> set[str]:
|
||||
return {
|
||||
constraint['name']
|
||||
for constraint in inspector.get_check_constraints(table_name)
|
||||
if constraint.get('name')
|
||||
}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""切换到订单解析确定性业务状态、Unit 摘要字段和新事件表。"""
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
run_checks = _check_constraints(inspector, 'shipping_order_extraction_runs')
|
||||
unit_checks = _check_constraints(inspector, 'shipping_order_extraction_units')
|
||||
|
||||
if 'ck_shipping_order_extraction_runs_status' in run_checks:
|
||||
op.drop_constraint('ck_shipping_order_extraction_runs_status', 'shipping_order_extraction_runs', type_='check')
|
||||
if 'ck_shipping_order_extraction_units_status' in unit_checks:
|
||||
op.drop_constraint('ck_shipping_order_extraction_units_status', 'shipping_order_extraction_units', type_='check')
|
||||
|
||||
# 兼容历史运行状态,避免存量数据在新增约束时失败。
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE shipping_order_extraction_runs
|
||||
SET status = CASE status
|
||||
WHEN 'running' THEN 'processing'
|
||||
WHEN 'result_persisted' THEN 'completed'
|
||||
WHEN 'needs_review' THEN 'review_required'
|
||||
ELSE status
|
||||
END
|
||||
WHERE status IN ('running', 'result_persisted', 'needs_review')
|
||||
"""
|
||||
)
|
||||
)
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE shipping_order_extraction_units
|
||||
SET status = CASE status
|
||||
WHEN 'running' THEN 'extracting'
|
||||
WHEN 'succeeded' THEN 'candidate_ready'
|
||||
WHEN 'skipped' THEN 'review_required'
|
||||
ELSE status
|
||||
END
|
||||
WHERE status IN ('running', 'succeeded', 'skipped')
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
with op.batch_alter_table('shipping_order_extraction_runs') as batch:
|
||||
batch.create_check_constraint(
|
||||
'ck_shipping_order_extraction_runs_status',
|
||||
"status IN ('queued', 'processing', 'completed', 'partially_completed', 'review_required', 'failed', 'cancelled')",
|
||||
)
|
||||
for index_name in ('uq_shipping_order_extraction_runs_active_conversation',):
|
||||
if index_name in _indexes(inspector, 'shipping_order_extraction_runs'):
|
||||
op.drop_index(index_name, table_name='shipping_order_extraction_runs')
|
||||
op.create_index(
|
||||
'uq_shipping_order_extraction_runs_active_conversation',
|
||||
'shipping_order_extraction_runs',
|
||||
['user_id', 'owner_agent_id', 'conversation_id'],
|
||||
unique=True,
|
||||
sqlite_where=sa.text("status IN ('queued', 'processing')"),
|
||||
postgresql_where=sa.text("status IN ('queued', 'processing')"),
|
||||
)
|
||||
|
||||
with op.batch_alter_table('shipping_order_extraction_units') as batch:
|
||||
batch.create_check_constraint(
|
||||
'ck_shipping_order_extraction_units_status',
|
||||
"status IN ('pending', 'routing', 'matching_profile', 'extracting', 'merging_supplement', 'candidate_ready', 'review_required', 'failed', 'cancelled')",
|
||||
)
|
||||
existing_columns = _columns(inspector, 'shipping_order_extraction_units')
|
||||
if 'reason_code' not in existing_columns:
|
||||
batch.add_column(sa.Column('reason_code', sa.String(length=64), nullable=True))
|
||||
if 'summary_json' not in existing_columns:
|
||||
batch.add_column(sa.Column('summary_json', sa.JSON(), nullable=True))
|
||||
if 'last_activity_at' not in existing_columns:
|
||||
batch.add_column(sa.Column('last_activity_at', sa.DateTime(), nullable=True))
|
||||
|
||||
if _has_table(inspector, 'shipping_order_extraction_progress_events'):
|
||||
op.drop_table('shipping_order_extraction_progress_events')
|
||||
op.create_table(
|
||||
'shipping_order_extraction_progress_events',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('run_id', sa.Integer(), sa.ForeignKey('shipping_order_extraction_runs.id', ondelete='CASCADE'), nullable=False),
|
||||
sa.Column('unit_id', sa.Integer(), sa.ForeignKey('shipping_order_extraction_units.id', ondelete='CASCADE'), nullable=True),
|
||||
sa.Column('document_id', sa.Integer(), nullable=True),
|
||||
sa.Column('job_id', sa.Integer(), sa.ForeignKey('jobs.id'), nullable=True),
|
||||
sa.Column('attempt_count', sa.Integer(), nullable=True),
|
||||
sa.Column('sequence_no', sa.Integer(), nullable=False),
|
||||
sa.Column('visibility', sa.String(length=32), nullable=False, server_default='workspace'),
|
||||
sa.Column('event_code', sa.String(length=64), nullable=False),
|
||||
sa.Column('status', sa.String(length=32), nullable=False, server_default='completed'),
|
||||
sa.Column('occurred_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('reason_code', sa.String(length=64), nullable=True),
|
||||
sa.Column('received_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('summary_json', sa.JSON(), nullable=True),
|
||||
sa.Column('idempotency_key', sa.String(length=128), nullable=False),
|
||||
sa.Column('mapping_version', sa.String(length=32), nullable=True),
|
||||
sa.Column('expires_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.UniqueConstraint('idempotency_key', name='uq_shipping_order_extraction_progress_event_key'),
|
||||
sa.UniqueConstraint('run_id', 'sequence_no', name='uq_shipping_order_extraction_progress_event_sequence'),
|
||||
)
|
||||
op.create_index(
|
||||
'ix_shipping_order_extraction_progress_events_run_sequence',
|
||||
'shipping_order_extraction_progress_events',
|
||||
['run_id', 'sequence_no'],
|
||||
)
|
||||
op.create_index(
|
||||
'ix_shipping_order_extraction_progress_events_expires_id',
|
||||
'shipping_order_extraction_progress_events',
|
||||
['expires_at', 'id'],
|
||||
)
|
||||
op.create_index(
|
||||
'ix_shipping_order_extraction_progress_events_run_visibility',
|
||||
'shipping_order_extraction_progress_events',
|
||||
['run_id', 'visibility', 'sequence_no'],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""恢复旧的 Workflow 观察器阶段结构,仅用于受控回滚。"""
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
|
||||
if _has_table(inspector, 'shipping_order_extraction_progress_events'):
|
||||
op.drop_table('shipping_order_extraction_progress_events')
|
||||
op.create_table(
|
||||
'shipping_order_extraction_progress_events',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('run_id', sa.Integer(), sa.ForeignKey('shipping_order_extraction_runs.id', ondelete='CASCADE'), nullable=False),
|
||||
sa.Column('job_id', sa.Integer(), sa.ForeignKey('jobs.id'), nullable=True),
|
||||
sa.Column('attempt_count', sa.Integer(), nullable=True),
|
||||
sa.Column('workflow_run_id', sa.String(length=128), nullable=True),
|
||||
sa.Column('node_execution_id', sa.String(length=128), nullable=True),
|
||||
sa.Column('event_type', sa.String(length=64), nullable=False),
|
||||
sa.Column('node_type', sa.String(length=64), nullable=True),
|
||||
sa.Column('stage_code', sa.String(length=64), nullable=True),
|
||||
sa.Column('event_status', sa.String(length=32), nullable=True),
|
||||
sa.Column('provider_occurred_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('received_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('details_json', sa.JSON(), nullable=True),
|
||||
sa.Column('idempotency_key', sa.String(length=128), nullable=False),
|
||||
sa.Column('mapping_version', sa.String(length=32), nullable=True),
|
||||
sa.Column('expires_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.UniqueConstraint('idempotency_key', name='uq_shipping_order_extraction_progress_event_key'),
|
||||
)
|
||||
op.create_index(
|
||||
'ix_shipping_order_extraction_progress_events_run_created',
|
||||
'shipping_order_extraction_progress_events',
|
||||
['run_id', 'created_at'],
|
||||
)
|
||||
op.create_index(
|
||||
'ix_shipping_order_extraction_progress_events_expires_id',
|
||||
'shipping_order_extraction_progress_events',
|
||||
['expires_at', 'id'],
|
||||
)
|
||||
op.create_index(
|
||||
'ix_shipping_order_extraction_progress_events_workflow_node',
|
||||
'shipping_order_extraction_progress_events',
|
||||
['workflow_run_id', 'node_execution_id'],
|
||||
)
|
||||
|
||||
with op.batch_alter_table('shipping_order_extraction_units') as batch:
|
||||
existing_columns = _columns(inspector, 'shipping_order_extraction_units')
|
||||
for column_name in ('last_activity_at', 'summary_json', 'reason_code'):
|
||||
if column_name in existing_columns:
|
||||
batch.drop_column(column_name)
|
||||
if 'ck_shipping_order_extraction_units_status' in _check_constraints(inspector, 'shipping_order_extraction_units'):
|
||||
batch.drop_constraint('ck_shipping_order_extraction_units_status', type_='check')
|
||||
batch.create_check_constraint(
|
||||
'ck_shipping_order_extraction_units_status',
|
||||
"status IN ('pending', 'running', 'succeeded', 'failed', 'skipped')",
|
||||
)
|
||||
|
||||
if 'uq_shipping_order_extraction_runs_active_conversation' in _indexes(inspector, 'shipping_order_extraction_runs'):
|
||||
op.drop_index('uq_shipping_order_extraction_runs_active_conversation', table_name='shipping_order_extraction_runs')
|
||||
op.create_index(
|
||||
'uq_shipping_order_extraction_runs_active_conversation',
|
||||
'shipping_order_extraction_runs',
|
||||
['user_id', 'owner_agent_id', 'conversation_id'],
|
||||
unique=True,
|
||||
sqlite_where=sa.text("status IN ('queued', 'running', 'result_persisted')"),
|
||||
postgresql_where=sa.text("status IN ('queued', 'running', 'result_persisted')"),
|
||||
)
|
||||
with op.batch_alter_table('shipping_order_extraction_runs') as batch:
|
||||
if 'ck_shipping_order_extraction_runs_status' in _check_constraints(inspector, 'shipping_order_extraction_runs'):
|
||||
batch.drop_constraint('ck_shipping_order_extraction_runs_status', type_='check')
|
||||
batch.create_check_constraint(
|
||||
'ck_shipping_order_extraction_runs_status',
|
||||
"status IN ('queued', 'running', 'result_persisted', 'completed', 'needs_review', 'failed', 'cancelled')",
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
"""Remove obsolete internal executor configuration.
|
||||
|
||||
Revision ID: 0ac56d7e8f90
|
||||
Revises: 1d2e3f4a5b6c, 3dd67e8f9a0b
|
||||
Create Date: 2026-07-28 16:20:00.000000
|
||||
|
||||
Purpose: remove the retired internal executor and runtime binding data model.
|
||||
Dependencies: agents and agent_runtime_bindings.
|
||||
Logic: delete obsolete bindings, normalize retained Agent records, then remove the exposure column and binding table.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '0ac56d7e8f90'
|
||||
down_revision = ('1d2e3f4a5b6c', '3dd67e8f9a0b')
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Permanently remove internal-executor semantics and their obsolete bindings."""
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
tables = set(inspector.get_table_names())
|
||||
if 'agent_runtime_bindings' in tables:
|
||||
bind.execute(sa.text('DELETE FROM agent_runtime_bindings'))
|
||||
|
||||
if 'agents' not in tables:
|
||||
return
|
||||
columns = {column['name'] for column in inspector.get_columns('agents')}
|
||||
if 'exposure_mode' not in columns:
|
||||
return
|
||||
|
||||
# Retain Agent rows because chats, guides, and historical Runs may reference them.
|
||||
# Removing the role column makes all retained records ordinary applications.
|
||||
bind.execute(sa.text("UPDATE agents SET exposure_mode = 'workspace' WHERE exposure_mode = 'internal'"))
|
||||
|
||||
inspector = sa.inspect(bind)
|
||||
if 'agent_runtime_bindings' in set(inspector.get_table_names()):
|
||||
op.drop_table('agent_runtime_bindings')
|
||||
with op.batch_alter_table('agents') as batch:
|
||||
constraints = {item['name'] for item in sa.inspect(bind).get_check_constraints('agents') if item.get('name')}
|
||||
if 'ck_agents_exposure_mode' in constraints:
|
||||
batch.drop_constraint('ck_agents_exposure_mode', type_='check')
|
||||
batch.drop_column('exposure_mode')
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""This intentional destructive cleanup has no downgrade path."""
|
||||
raise RuntimeError('Internal executor removal cannot be downgraded')
|
||||
@@ -0,0 +1,55 @@
|
||||
"""align order route decision constraint
|
||||
|
||||
Revision ID: 0bd56e7f8a91
|
||||
Revises: 0ac56d7e8f90
|
||||
Create Date: 2026-07-28 14:00:00.000000
|
||||
|
||||
用途:使数据库路由决策约束与确定性订单抽取模型一致。
|
||||
依赖:shipping_order_extraction_route_decisions、ShippingOrderExtractionRouteDecision。
|
||||
逻辑:替换历史 decision 枚举约束,允许 deterministic、review_required 与 skipped;不修改已有审计数据。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '0bd56e7f8a91'
|
||||
down_revision = '0ac56d7e8f90'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""替换遗留的路由 decision 检查约束,支持人工复核和跳过投影。"""
|
||||
op.drop_constraint(
|
||||
'ck_shipping_order_extraction_route_decision',
|
||||
'shipping_order_extraction_route_decisions',
|
||||
type_='check',
|
||||
)
|
||||
# 历史 dify/blocked 仅是旧路由语义:分别映射为当前确定性/人工复核投影。
|
||||
op.execute(
|
||||
"UPDATE shipping_order_extraction_route_decisions "
|
||||
"SET decision = CASE decision "
|
||||
"WHEN 'dify' THEN 'deterministic' "
|
||||
"WHEN 'blocked' THEN 'review_required' "
|
||||
"ELSE decision END "
|
||||
"WHERE decision IN ('dify', 'blocked')"
|
||||
)
|
||||
op.create_check_constraint(
|
||||
'ck_shipping_order_extraction_route_decision',
|
||||
'shipping_order_extraction_route_decisions',
|
||||
"decision IN ('deterministic', 'review_required', 'skipped')",
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""恢复历史枚举,回退前须确认不存在新 decision 值。"""
|
||||
op.drop_constraint(
|
||||
'ck_shipping_order_extraction_route_decision',
|
||||
'shipping_order_extraction_route_decisions',
|
||||
type_='check',
|
||||
)
|
||||
op.create_check_constraint(
|
||||
'ck_shipping_order_extraction_route_decision',
|
||||
'shipping_order_extraction_route_decisions',
|
||||
"decision IN ('deterministic', 'dify', 'blocked')",
|
||||
)
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
"""add customer and scenario scope to profile auto-freeze qualifications
|
||||
|
||||
Revision ID: 0ce67f8a9b01
|
||||
Revises: 0bd56e7f8a91
|
||||
Create Date: 2026-07-28 18:40:00.000000
|
||||
|
||||
用途:为模板版本级自动冻结资格补齐客户/业务场景授权范围。
|
||||
依赖:已存在的自动冻结资格表与用户表。
|
||||
逻辑:仅追加授权范围与配置审计字段,不改变既有资格状态。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '0ce67f8a9b01'
|
||||
down_revision = '0bd56e7f8a91'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""为资格表增加客户范围、业务场景和客户确认开关。"""
|
||||
with op.batch_alter_table('shipping_document_profile_auto_freeze_qualifications', recreate='auto') as batch_op:
|
||||
batch_op.add_column(sa.Column('customer_ids_json', sa.JSON(), nullable=True))
|
||||
batch_op.add_column(sa.Column('business_scenarios_json', sa.JSON(), nullable=True))
|
||||
batch_op.add_column(
|
||||
sa.Column('requires_customer_confirmation', sa.Boolean(), nullable=False, server_default=sa.text('true')),
|
||||
)
|
||||
batch_op.add_column(sa.Column('scope_updated_by_id', sa.Integer(), nullable=True))
|
||||
batch_op.add_column(sa.Column('scope_updated_at', sa.DateTime(), nullable=True))
|
||||
batch_op.create_foreign_key(
|
||||
'fk_ship_doc_prof_auto_freeze_scope_updated_by_user',
|
||||
'users',
|
||||
['scope_updated_by_id'],
|
||||
['id'],
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除资格范围字段,保留既有状态记录。"""
|
||||
with op.batch_alter_table('shipping_document_profile_auto_freeze_qualifications', recreate='auto') as batch_op:
|
||||
batch_op.drop_constraint('fk_ship_doc_prof_auto_freeze_scope_updated_by_user', type_='foreignkey')
|
||||
batch_op.drop_column('scope_updated_at')
|
||||
batch_op.drop_column('scope_updated_by_id')
|
||||
batch_op.drop_column('requires_customer_confirmation')
|
||||
batch_op.drop_column('business_scenarios_json')
|
||||
batch_op.drop_column('customer_ids_json')
|
||||
@@ -0,0 +1,38 @@
|
||||
"""add upload batch to shipping notice intakes
|
||||
|
||||
Revision ID: 0cf78a9b0c12
|
||||
Revises: 0ce67f8a9b01
|
||||
Create Date: 2026-07-28 20:10:00.000000
|
||||
|
||||
用途:为聊天输入框的一次文件选择持久化上传批次。
|
||||
依赖:shipping_notice_intakes。
|
||||
逻辑:Run 创建按 upload_batch_id 锁定当前发送附件,避免历史未发送 Intake 混入。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '0cf78a9b0c12'
|
||||
down_revision = '0ce67f8a9b01'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""新增上传批次与按用户批次查询索引;无历史兼容回填。"""
|
||||
with op.batch_alter_table('shipping_notice_intakes', recreate='auto') as batch_op:
|
||||
# 旧 Intake 不回填也不可发送;可空使已有生产表能够原地升级。
|
||||
batch_op.add_column(sa.Column('upload_batch_id', sa.String(length=36), nullable=True))
|
||||
batch_op.create_index(
|
||||
'ix_shipping_notice_intakes_user_upload_batch_created',
|
||||
['user_id', 'upload_batch_id', 'created_at'],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除输入框上传批次字段和索引。"""
|
||||
with op.batch_alter_table('shipping_notice_intakes', recreate='auto') as batch_op:
|
||||
batch_op.drop_index('ix_shipping_notice_intakes_user_upload_batch_created')
|
||||
batch_op.drop_column('upload_batch_id')
|
||||
@@ -0,0 +1,63 @@
|
||||
"""add order extraction unit plan metadata
|
||||
|
||||
Revision ID: 1d2e3f4a5b6c
|
||||
Revises: 0ab45c6d7e8f
|
||||
Create Date: 2026-07-28 17:10:00.000000
|
||||
|
||||
用途:为订单抽取单元补充选择批次、分组键、预算、重试与技术失败事实。
|
||||
依赖:shipping_order_extraction_units。
|
||||
逻辑:阶段 2/4 直接在 Unit 层持久化计划与失败元数据,避免后续只能回读 snapshot 猜测。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '1d2e3f4a5b6c'
|
||||
down_revision = '0ab45c6d7e8f'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _columns(inspector: sa.Inspector, table_name: str) -> set[str]:
|
||||
return {column['name'] for column in inspector.get_columns(table_name)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""为订单抽取单元添加阶段 2/4 所需的计划与失败元数据字段。"""
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
existing_columns = _columns(inspector, 'shipping_order_extraction_units')
|
||||
|
||||
with op.batch_alter_table('shipping_order_extraction_units') as batch:
|
||||
if 'selection_batch' not in existing_columns:
|
||||
batch.add_column(sa.Column('selection_batch', sa.Integer(), nullable=True))
|
||||
if 'selection_reason_codes_json' not in existing_columns:
|
||||
batch.add_column(sa.Column('selection_reason_codes_json', sa.JSON(), nullable=True))
|
||||
if 'group_key' not in existing_columns:
|
||||
batch.add_column(sa.Column('group_key', sa.String(length=128), nullable=True))
|
||||
if 'budget_cost_json' not in existing_columns:
|
||||
batch.add_column(sa.Column('budget_cost_json', sa.JSON(), nullable=True))
|
||||
if 'retry_status' not in existing_columns:
|
||||
batch.add_column(sa.Column('retry_status', sa.String(length=32), nullable=True))
|
||||
if 'technical_failure_reason_code' not in existing_columns:
|
||||
batch.add_column(sa.Column('technical_failure_reason_code', sa.String(length=64), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除订单抽取单元的计划与失败元数据字段。"""
|
||||
bind = op.get_bind()
|
||||
inspector = sa.inspect(bind)
|
||||
existing_columns = _columns(inspector, 'shipping_order_extraction_units')
|
||||
|
||||
with op.batch_alter_table('shipping_order_extraction_units') as batch:
|
||||
for column_name in (
|
||||
'technical_failure_reason_code',
|
||||
'retry_status',
|
||||
'budget_cost_json',
|
||||
'group_key',
|
||||
'selection_reason_codes_json',
|
||||
'selection_batch',
|
||||
):
|
||||
if column_name in existing_columns:
|
||||
batch.drop_column(column_name)
|
||||
@@ -0,0 +1,33 @@
|
||||
"""add immutable request snapshot to order extraction run
|
||||
|
||||
Revision ID: 2d3e4f5a6b7c
|
||||
Revises: 0cf78a9b0c12
|
||||
Create Date: 2026-07-28 21:15:00.000000
|
||||
|
||||
用途:保留用户点击发送时的轻量请求快照,隔离 Worker 物化后的执行快照。
|
||||
依赖:shipping_order_extraction_runs。
|
||||
逻辑:请求快照稳定用于幂等和审计;input_snapshot_* 继续承载不可变执行证据。
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision = '2d3e4f5a6b7c'
|
||||
down_revision = '0cf78a9b0c12'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""新增请求时冻结的哈希及 JSON 快照;旧记录保留为空。"""
|
||||
with op.batch_alter_table('shipping_order_extraction_runs', recreate='auto') as batch_op:
|
||||
batch_op.add_column(sa.Column('request_snapshot_hash', sa.String(length=64), nullable=True))
|
||||
batch_op.add_column(sa.Column('request_snapshot_json', sa.JSON(), nullable=True))
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除请求快照字段。"""
|
||||
with op.batch_alter_table('shipping_order_extraction_runs', recreate='auto') as batch_op:
|
||||
batch_op.drop_column('request_snapshot_json')
|
||||
batch_op.drop_column('request_snapshot_hash')
|
||||
Reference in new issue
Block a user