feat(shipping-notice): 增强订单文档 Profile 管理功能,新增复核与草稿管理
- 添加订单复核相关模型及 API,支持复核案例的创建、更新和确认 - 实现复核草稿的管理功能,允许用户对复核内容进行编辑和保存 - 引入复核事件审计,确保复核过程的可追溯性 - 更新数据库模型以支持复核和草稿的关系管理 - 完善相关服务逻辑,确保复核与草稿的状态管理和数据一致性 - 增强文档模板的管理能力,支持更复杂的业务场景
This commit is contained in:
1 parent
61ac6403c4
commit
b7307fc573
147 files changed
+15108
-1522
No files matched your search
@@ -0,0 +1,32 @@
|
||||
"""Repair review-confirmation tasks that were incorrectly reopened for parse review.
|
||||
|
||||
Revision ID: 0a1b2c3d4e5f
|
||||
Revises: ae0f1a2b3c4d
|
||||
Create Date: 2026-07-29
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '0a1b2c3d4e5f'
|
||||
down_revision = 'ae0f1a2b3c4d'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
"""Only repair tasks created by confirmed review Cases and left in the old erroneous state."""
|
||||
op.execute(
|
||||
"""
|
||||
UPDATE shipping_tasks
|
||||
SET process_status = 'parsed', review_status = NULL, pending_human_reason = NULL
|
||||
WHERE source_type = 'review_confirmation'
|
||||
AND process_status = 'pending_review'
|
||||
AND review_status = 'parse_review'
|
||||
AND pending_human_reason = 'low_confidence'
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
"""State repair is intentionally irreversible: the old state was invalid workflow data."""
|
||||
@@ -0,0 +1,65 @@
|
||||
"""freeze order profile sample evidence
|
||||
|
||||
Revision ID: 3e4f5a6b7c8d
|
||||
Revises: 2d3e4f5a6b7c
|
||||
Create Date: 2026-07-28 22:30:00.000000
|
||||
|
||||
用途:为订单模板样本绑定补齐发布时冻结的 Layout/Parser/摘要证据字段。
|
||||
依赖:现有 shipping_order_document_profile_samples、shipping_document_layout_versions 与 users 表。
|
||||
逻辑:仅追加冻结证据列与索引,不回填旧历史数据,旧记录保持空值等待受控重建。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = '3e4f5a6b7c8d'
|
||||
down_revision = '2d3e4f5a6b7c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""为模板样本绑定增加冻结 Layout 证据和安全展示摘要。"""
|
||||
with op.batch_alter_table('shipping_order_document_profile_samples', recreate='auto') as batch_op:
|
||||
batch_op.add_column(sa.Column('layout_version_id', sa.Integer(), nullable=True))
|
||||
batch_op.add_column(sa.Column('source_content_hash', sa.String(length=64), nullable=True))
|
||||
batch_op.add_column(sa.Column('layout_payload_checksum', sa.String(length=64), nullable=True))
|
||||
batch_op.add_column(sa.Column('layout_contract_version', sa.String(length=64), nullable=True))
|
||||
batch_op.add_column(sa.Column('parser_key', sa.String(length=128), nullable=True))
|
||||
batch_op.add_column(sa.Column('parser_name', sa.String(length=32), nullable=True))
|
||||
batch_op.add_column(sa.Column('parser_version', sa.String(length=64), nullable=True))
|
||||
batch_op.add_column(sa.Column('evidence_frozen_at', sa.DateTime(), nullable=True))
|
||||
batch_op.add_column(sa.Column('source_filename_snapshot', sa.String(length=255), nullable=True))
|
||||
batch_op.add_column(sa.Column('page_count_snapshot', sa.Integer(), nullable=True))
|
||||
batch_op.add_column(sa.Column('table_identity_snapshot', sa.JSON(), nullable=True))
|
||||
batch_op.create_foreign_key(
|
||||
'fk_ship_order_profile_sample_layout_version',
|
||||
'shipping_document_layout_versions',
|
||||
['layout_version_id'],
|
||||
['id'],
|
||||
)
|
||||
batch_op.create_index(
|
||||
'ix_shipping_order_document_profile_samples_layout_version',
|
||||
['layout_version_id'],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除模板样本冻结证据列,回退到仅保留文档绑定的旧结构。"""
|
||||
with op.batch_alter_table('shipping_order_document_profile_samples', recreate='auto') as batch_op:
|
||||
batch_op.drop_index('ix_shipping_order_document_profile_samples_layout_version')
|
||||
batch_op.drop_constraint('fk_ship_order_profile_sample_layout_version', type_='foreignkey')
|
||||
batch_op.drop_column('table_identity_snapshot')
|
||||
batch_op.drop_column('page_count_snapshot')
|
||||
batch_op.drop_column('source_filename_snapshot')
|
||||
batch_op.drop_column('evidence_frozen_at')
|
||||
batch_op.drop_column('parser_version')
|
||||
batch_op.drop_column('parser_name')
|
||||
batch_op.drop_column('parser_key')
|
||||
batch_op.drop_column('layout_contract_version')
|
||||
batch_op.drop_column('layout_payload_checksum')
|
||||
batch_op.drop_column('source_content_hash')
|
||||
batch_op.drop_column('layout_version_id')
|
||||
@@ -0,0 +1,104 @@
|
||||
"""create shipping order review domain
|
||||
|
||||
Revision ID: 4f5a6b7c8d9e
|
||||
Revises: 3e4f5a6b7c8d
|
||||
Create Date: 2026-07-28 23:30:00.000000
|
||||
|
||||
用途:创建建单前订单人工复核的 Case、Draft 与追加式事件表。
|
||||
依赖:订单抽取 Run/Unit、Candidate、Schema、Task 和 users。
|
||||
逻辑:Unit 唯一约束保证一份 PDF 只能创建一个 Case;Case 与 Draft 分表,
|
||||
避免人工编辑覆盖机器 Candidate。确认 Task 关联保持唯一,供后续阶段原子确认使用。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '4f5a6b7c8d9e'
|
||||
down_revision = '3e4f5a6b7c8d'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""建立 Review Case/Draft/Event 表以及 PDF Unit 和确认 Task 的唯一门禁。"""
|
||||
op.create_table(
|
||||
'shipping_order_review_cases',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('case_no', sa.String(length=64), nullable=False),
|
||||
sa.Column('run_id', sa.Integer(), nullable=False),
|
||||
sa.Column('unit_id', sa.Integer(), nullable=False),
|
||||
sa.Column('document_id', sa.Integer(), nullable=False),
|
||||
sa.Column('candidate_id', sa.Integer(), nullable=True),
|
||||
sa.Column('owner_user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('status', sa.String(length=32), nullable=False, server_default='unreviewed'),
|
||||
sa.Column('disposition', sa.String(length=32), nullable=True),
|
||||
sa.Column('current_draft_id', sa.Integer(), nullable=True),
|
||||
sa.Column('confirmed_task_id', sa.Integer(), nullable=True),
|
||||
sa.Column('confirmed_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
||||
sa.CheckConstraint("status IN ('unreviewed', 'draft', 'ready', 'confirming', 'confirmed', 'non_order', 'quality_issue', 'reparse_pending', 'superseded')", name='ck_shipping_order_review_cases_status'),
|
||||
sa.ForeignKeyConstraint(['run_id'], ['shipping_order_extraction_runs.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['unit_id'], ['shipping_order_extraction_units.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['document_id'], ['shipping_notice_documents.id']),
|
||||
sa.ForeignKeyConstraint(['candidate_id'], ['shipping_notice_candidates.id']),
|
||||
sa.ForeignKeyConstraint(['owner_user_id'], ['users.id']),
|
||||
sa.ForeignKeyConstraint(['confirmed_task_id'], ['shipping_tasks.id']),
|
||||
sa.UniqueConstraint('case_no', name='uq_shipping_order_review_cases_no'),
|
||||
sa.UniqueConstraint('unit_id', name='uq_shipping_order_review_cases_unit'),
|
||||
sa.UniqueConstraint('confirmed_task_id', name='uq_shipping_order_review_cases_confirmed_task'),
|
||||
)
|
||||
op.create_index('ix_shipping_order_review_cases_run_status', 'shipping_order_review_cases', ['run_id', 'status'])
|
||||
op.create_index('ix_shipping_order_review_cases_owner_updated', 'shipping_order_review_cases', ['owner_user_id', 'updated_at'])
|
||||
op.create_table(
|
||||
'shipping_order_review_drafts',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('case_id', sa.Integer(), nullable=False),
|
||||
sa.Column('draft_version', sa.Integer(), nullable=False, server_default='1'),
|
||||
sa.Column('schema_version_id', sa.Integer(), nullable=False),
|
||||
sa.Column('header_values_json', sa.JSON(), nullable=False),
|
||||
sa.Column('lines_json', sa.JSON(), nullable=False),
|
||||
sa.Column('issue_summary_json', sa.JSON(), nullable=False),
|
||||
sa.Column('validation_result_json', sa.JSON(), nullable=False),
|
||||
sa.Column('change_reason_json', sa.JSON(), nullable=False),
|
||||
sa.Column('updated_by_id', sa.Integer(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
||||
sa.CheckConstraint('draft_version >= 1', name='ck_shipping_order_review_drafts_version'),
|
||||
sa.ForeignKeyConstraint(['case_id'], ['shipping_order_review_cases.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['schema_version_id'], ['shipping_order_schema_versions.id']),
|
||||
sa.ForeignKeyConstraint(['updated_by_id'], ['users.id']),
|
||||
sa.UniqueConstraint('case_id', 'draft_version', name='uq_shipping_order_review_drafts_case_version'),
|
||||
)
|
||||
op.create_index('ix_shipping_order_review_drafts_case_updated', 'shipping_order_review_drafts', ['case_id', 'updated_at'])
|
||||
with op.batch_alter_table('shipping_order_review_cases', recreate='auto') as batch_op:
|
||||
batch_op.create_foreign_key('fk_shipping_order_review_cases_current_draft', 'shipping_order_review_drafts', ['current_draft_id'], ['id'])
|
||||
op.create_table(
|
||||
'shipping_order_review_case_events',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('case_id', sa.Integer(), nullable=False),
|
||||
sa.Column('event_type', sa.String(length=64), nullable=False),
|
||||
sa.Column('draft_version', sa.Integer(), nullable=True),
|
||||
sa.Column('actor_user_id', sa.Integer(), nullable=True),
|
||||
sa.Column('operation_json', sa.JSON(), nullable=False),
|
||||
sa.Column('occurred_at', sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['case_id'], ['shipping_order_review_cases.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['actor_user_id'], ['users.id']),
|
||||
)
|
||||
op.create_index('ix_shipping_order_review_case_events_case_occurred', 'shipping_order_review_case_events', ['case_id', 'occurred_at'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""按依赖逆序删除复核领域表,供隔离环境迁移往返验证。"""
|
||||
op.drop_index('ix_shipping_order_review_case_events_case_occurred', table_name='shipping_order_review_case_events')
|
||||
op.drop_table('shipping_order_review_case_events')
|
||||
with op.batch_alter_table('shipping_order_review_cases', recreate='auto') as batch_op:
|
||||
batch_op.drop_constraint('fk_shipping_order_review_cases_current_draft', type_='foreignkey')
|
||||
op.drop_index('ix_shipping_order_review_drafts_case_updated', table_name='shipping_order_review_drafts')
|
||||
op.drop_table('shipping_order_review_drafts')
|
||||
op.drop_index('ix_shipping_order_review_cases_owner_updated', table_name='shipping_order_review_cases')
|
||||
op.drop_index('ix_shipping_order_review_cases_run_status', table_name='shipping_order_review_cases')
|
||||
op.drop_table('shipping_order_review_cases')
|
||||
@@ -0,0 +1,54 @@
|
||||
"""add profile governance indexes
|
||||
|
||||
Revision ID: 5a6b7c8d9e0f
|
||||
Revises: 4f5a6b7c8d9e
|
||||
Create Date: 2026-07-28 22:55:00.000000
|
||||
|
||||
用途:为模板版本审计请求链路和实际使用查询补齐 request_id 列与受控索引。
|
||||
依赖:shipping_order_document_profile_audits、shipping_order_extraction_route_decisions 现有主表。
|
||||
逻辑:只追加列与索引,不回填历史 request_id;旧审计记录保持空值但仍可回放。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = '5a6b7c8d9e0f'
|
||||
down_revision = '4f5a6b7c8d9e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""增加 profile 审计 request_id 和版本使用查询索引。"""
|
||||
with op.batch_alter_table('shipping_order_document_profile_audits', recreate='auto') as batch_op:
|
||||
batch_op.add_column(sa.Column('request_id', sa.String(length=64), nullable=True))
|
||||
batch_op.create_index(
|
||||
'ix_shipping_order_document_profile_audits_profile_request',
|
||||
['profile_id', 'request_id', 'id'],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
with op.batch_alter_table('shipping_order_extraction_route_decisions', recreate='auto') as batch_op:
|
||||
batch_op.create_index(
|
||||
'ix_shipping_order_extraction_route_decisions_profile_id',
|
||||
['selected_profile_id', 'id'],
|
||||
unique=False,
|
||||
)
|
||||
batch_op.create_index(
|
||||
'ix_shipping_order_extraction_route_decisions_profile_snapshot',
|
||||
['selected_profile_code', 'selected_profile_version', 'selected_profile_checksum', 'id'],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除模板治理查询新增索引与 request_id 列。"""
|
||||
with op.batch_alter_table('shipping_order_extraction_route_decisions', recreate='auto') as batch_op:
|
||||
batch_op.drop_index('ix_shipping_order_extraction_route_decisions_profile_snapshot')
|
||||
batch_op.drop_index('ix_shipping_order_extraction_route_decisions_profile_id')
|
||||
|
||||
with op.batch_alter_table('shipping_order_document_profile_audits', recreate='auto') as batch_op:
|
||||
batch_op.drop_index('ix_shipping_order_document_profile_audits_profile_request')
|
||||
batch_op.drop_column('request_id')
|
||||
@@ -0,0 +1,53 @@
|
||||
"""add shipping review confirmed revision
|
||||
|
||||
Revision ID: 6b7c8d9e0f1a
|
||||
Revises: 5a6b7c8d9e0f
|
||||
Create Date: 2026-07-29 09:30:00.000000
|
||||
|
||||
用途:持久化 PDF 复核草稿确认时的不可变版本。
|
||||
依赖:Review Case/Draft、订单 Schema、ShippingTask 和 users。
|
||||
逻辑:Case 与幂等键均唯一,保证重复确认只返回同一 Task,不能重放为另一张订单。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '6b7c8d9e0f1a'
|
||||
down_revision = '5a6b7c8d9e0f'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""创建确认快照表及其 Case、幂等和 Task 查询约束。"""
|
||||
op.create_table(
|
||||
'shipping_order_review_confirmed_revisions',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('case_id', sa.Integer(), nullable=False),
|
||||
sa.Column('task_id', sa.Integer(), nullable=False),
|
||||
sa.Column('draft_version', sa.Integer(), nullable=False),
|
||||
sa.Column('schema_version_id', sa.Integer(), nullable=False),
|
||||
sa.Column('header_values_json', sa.JSON(), nullable=False),
|
||||
sa.Column('lines_json', sa.JSON(), nullable=False),
|
||||
sa.Column('validation_result_json', sa.JSON(), nullable=False),
|
||||
sa.Column('warning_acknowledgements_json', sa.JSON(), nullable=False),
|
||||
sa.Column('idempotency_key', sa.String(length=128), nullable=False),
|
||||
sa.Column('confirmed_by_id', sa.Integer(), nullable=False),
|
||||
sa.Column('confirmed_at', sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['case_id'], ['shipping_order_review_cases.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['task_id'], ['shipping_tasks.id']),
|
||||
sa.ForeignKeyConstraint(['schema_version_id'], ['shipping_order_schema_versions.id']),
|
||||
sa.ForeignKeyConstraint(['confirmed_by_id'], ['users.id']),
|
||||
sa.UniqueConstraint('case_id', name='uq_shipping_order_review_confirmed_revisions_case'),
|
||||
sa.UniqueConstraint('idempotency_key', name='uq_shipping_order_review_confirmed_revisions_idempotency'),
|
||||
)
|
||||
op.create_index('ix_shipping_order_review_confirmed_revisions_task', 'shipping_order_review_confirmed_revisions', ['task_id'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""删除确认快照表,按创建顺序逆向回滚。"""
|
||||
op.drop_index('ix_shipping_order_review_confirmed_revisions_task', table_name='shipping_order_review_confirmed_revisions')
|
||||
op.drop_table('shipping_order_review_confirmed_revisions')
|
||||
@@ -0,0 +1,81 @@
|
||||
"""add order profile draft governance
|
||||
|
||||
Revision ID: 7c8d9e0f1a2b
|
||||
Revises: 6b7c8d9e0f1a
|
||||
Create Date: 2026-07-29 12:00:00.000000
|
||||
|
||||
用途:为订单模板草稿增加不可变修订、单写者租约和操作链路审计字段。
|
||||
依赖:订单模板 Profile 与现有 Profile 审计表。
|
||||
逻辑:新增表均以 Profile 外键级联清理;审计仅追加关联身份,不回填历史敏感详情。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '7c8d9e0f1a2b'
|
||||
down_revision = '6b7c8d9e0f1a'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""创建 Revision/Lease 表并扩展审计操作身份。"""
|
||||
op.create_table(
|
||||
'shipping_order_document_profile_draft_revisions',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||
sa.Column('revision_no', sa.Integer(), nullable=False),
|
||||
sa.Column('base_lock_version', sa.Integer(), nullable=False),
|
||||
sa.Column('result_lock_version', sa.Integer(), nullable=False),
|
||||
sa.Column('definition_checksum', sa.String(length=64), nullable=False),
|
||||
sa.Column('change_source', sa.String(length=32), nullable=False),
|
||||
sa.Column('actor_id', sa.Integer(), nullable=True),
|
||||
sa.Column('browser_session_id', sa.String(length=128), nullable=True),
|
||||
sa.Column('operation_id', sa.String(length=64), nullable=False),
|
||||
sa.Column('change_summary_json', sa.JSON(), nullable=False),
|
||||
sa.Column('definition_snapshot_json', sa.JSON(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['profile_id'], ['shipping_order_document_profiles.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['actor_id'], ['users.id']),
|
||||
sa.UniqueConstraint('profile_id', 'revision_no', name='uq_shipping_order_document_profile_draft_revisions_number'),
|
||||
sa.UniqueConstraint('profile_id', 'operation_id', name='uq_shipping_order_document_profile_draft_revisions_operation'),
|
||||
)
|
||||
op.create_index('ix_shipping_order_document_profile_draft_revisions_operation', 'shipping_order_document_profile_draft_revisions', ['operation_id'])
|
||||
op.create_table(
|
||||
'shipping_order_document_profile_edit_leases',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||
sa.Column('lease_token_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('actor_id', sa.Integer(), nullable=True),
|
||||
sa.Column('browser_session_id', sa.String(length=128), nullable=False),
|
||||
sa.Column('expires_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('last_renewed_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('taken_over_from_actor_id', sa.Integer(), nullable=True),
|
||||
sa.Column('lock_version', sa.Integer(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['profile_id'], ['shipping_order_document_profiles.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['actor_id'], ['users.id']),
|
||||
sa.ForeignKeyConstraint(['taken_over_from_actor_id'], ['users.id']),
|
||||
sa.UniqueConstraint('profile_id', name='uq_shipping_order_document_profile_edit_leases_profile'),
|
||||
)
|
||||
op.create_index('ix_shipping_order_document_profile_edit_leases_expires', 'shipping_order_document_profile_edit_leases', ['expires_at'])
|
||||
with op.batch_alter_table('shipping_order_document_profile_audits', recreate='auto') as batch_op:
|
||||
batch_op.add_column(sa.Column('operation_id', sa.String(length=64), nullable=True))
|
||||
batch_op.add_column(sa.Column('browser_session_id', sa.String(length=128), nullable=True))
|
||||
batch_op.add_column(sa.Column('revision_no', sa.Integer(), nullable=True))
|
||||
batch_op.create_index('ix_shipping_order_document_profile_audits_operation', ['operation_id', 'id'], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""按依赖反序删除草稿治理扩展。"""
|
||||
with op.batch_alter_table('shipping_order_document_profile_audits', recreate='auto') as batch_op:
|
||||
batch_op.drop_index('ix_shipping_order_document_profile_audits_operation')
|
||||
batch_op.drop_column('revision_no')
|
||||
batch_op.drop_column('browser_session_id')
|
||||
batch_op.drop_column('operation_id')
|
||||
op.drop_index('ix_shipping_order_document_profile_edit_leases_expires', table_name='shipping_order_document_profile_edit_leases')
|
||||
op.drop_table('shipping_order_document_profile_edit_leases')
|
||||
op.drop_index('ix_shipping_order_document_profile_draft_revisions_operation', table_name='shipping_order_document_profile_draft_revisions')
|
||||
op.drop_table('shipping_order_document_profile_draft_revisions')
|
||||
@@ -0,0 +1,33 @@
|
||||
"""add order profile suggestion decisions
|
||||
|
||||
Revision ID: 8d9e0f1a2b3c
|
||||
Revises: 7c8d9e0f1a2b
|
||||
Create Date: 2026-07-29 13:00:00.000000
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = '8d9e0f1a2b3c'
|
||||
down_revision = '7c8d9e0f1a2b'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
def upgrade() -> None:
|
||||
"""创建建议决定表,保留算法身份和管理员决定但不复制文档正文。"""
|
||||
op.create_table('shipping_order_document_profile_suggestion_decisions',
|
||||
sa.Column('id', sa.Integer(), primary_key=True), sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||
sa.Column('revision_no', sa.Integer(), nullable=False), sa.Column('sample_binding_id', sa.Integer()), sa.Column('layout_version_id', sa.Integer()),
|
||||
sa.Column('parser_key', sa.String(length=128)), sa.Column('parser_version', sa.String(length=64)), sa.Column('schema_version_id', sa.Integer(), nullable=False),
|
||||
sa.Column('algorithm_version', sa.String(length=64), nullable=False), sa.Column('suggestion_id', sa.String(length=64), nullable=False), sa.Column('suggestion_checksum', sa.String(length=64), nullable=False),
|
||||
sa.Column('decision', sa.String(length=24), nullable=False), sa.Column('actor_id', sa.Integer()), sa.Column('operation_id', sa.String(length=64), nullable=False), sa.Column('detail_json', sa.JSON(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.CheckConstraint("decision IN ('accepted', 'accepted_adjusted', 'rejected')", name='ck_order_profile_suggestion_decision'),
|
||||
sa.ForeignKeyConstraint(['profile_id'], ['shipping_order_document_profiles.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['sample_binding_id'], ['shipping_order_document_profile_samples.id'], ondelete='SET NULL'), sa.ForeignKeyConstraint(['layout_version_id'], ['shipping_document_layout_versions.id']), sa.ForeignKeyConstraint(['schema_version_id'], ['shipping_order_schema_versions.id']), sa.ForeignKeyConstraint(['actor_id'], ['users.id']),
|
||||
sa.UniqueConstraint('profile_id', 'suggestion_id', name='uq_order_profile_suggestion'))
|
||||
op.create_index('ix_order_profile_suggestion_revision', 'shipping_order_document_profile_suggestion_decisions', ['profile_id', 'revision_no'])
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除建议决定事实表。"""
|
||||
op.drop_index('ix_order_profile_suggestion_revision', table_name='shipping_order_document_profile_suggestion_decisions')
|
||||
op.drop_table('shipping_order_document_profile_suggestion_decisions')
|
||||
@@ -0,0 +1,26 @@
|
||||
"""add order profile validation runs
|
||||
|
||||
Revision ID: 9e0f1a2b3c4d
|
||||
Revises: 8d9e0f1a2b3c
|
||||
Create Date: 2026-07-29 14:00:00.000000
|
||||
"""
|
||||
from __future__ import annotations
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
revision = '9e0f1a2b3c4d'
|
||||
down_revision = '8d9e0f1a2b3c'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
def upgrade() -> None:
|
||||
"""创建不可变验证运行,冻结草稿、Schema 和样本证据身份。"""
|
||||
op.create_table('shipping_order_document_profile_validation_runs',
|
||||
sa.Column('id', sa.Integer(), primary_key=True), sa.Column('profile_id', sa.Integer(), nullable=False), sa.Column('revision_no', sa.Integer(), nullable=False), sa.Column('definition_checksum', sa.String(length=64), nullable=False), sa.Column('schema_version_id', sa.Integer(), nullable=False), sa.Column('schema_checksum', sa.String(length=64)), sa.Column('sample_binding_id', sa.Integer()), sa.Column('layout_version_id', sa.Integer()), sa.Column('layout_payload_checksum', sa.String(length=64)), sa.Column('parser_key', sa.String(length=128)), sa.Column('parser_version', sa.String(length=64)), sa.Column('run_type', sa.String(length=32), nullable=False), sa.Column('status', sa.String(length=16), nullable=False), sa.Column('summary_json', sa.JSON(), nullable=False), sa.Column('result_snapshot_json', sa.JSON(), nullable=False), sa.Column('operation_id', sa.String(length=64), nullable=False), sa.Column('actor_id', sa.Integer()), sa.Column('created_at', sa.DateTime(), nullable=False), sa.Column('completed_at', sa.DateTime()),
|
||||
sa.CheckConstraint("run_type IN ('instant_check', 'current_sample', 'blind_test', 'scenario_coverage', 'schema_compatibility')", name='ck_shipping_order_document_profile_validation_runs_type'), sa.CheckConstraint("status IN ('pending', 'running', 'passed', 'failed')", name='ck_shipping_order_document_profile_validation_runs_status'),
|
||||
sa.ForeignKeyConstraint(['profile_id'], ['shipping_order_document_profiles.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['schema_version_id'], ['shipping_order_schema_versions.id']), sa.ForeignKeyConstraint(['sample_binding_id'], ['shipping_order_document_profile_samples.id'], ondelete='SET NULL'), sa.ForeignKeyConstraint(['layout_version_id'], ['shipping_document_layout_versions.id']), sa.ForeignKeyConstraint(['actor_id'], ['users.id']))
|
||||
op.create_index('ix_order_profile_validation_created', 'shipping_order_document_profile_validation_runs', ['profile_id', 'created_at'])
|
||||
op.create_index('ix_order_profile_validation_checksum', 'shipping_order_document_profile_validation_runs', ['profile_id', 'definition_checksum'])
|
||||
def downgrade() -> None:
|
||||
"""移除验证运行。"""
|
||||
op.drop_index('ix_order_profile_validation_checksum', table_name='shipping_order_document_profile_validation_runs')
|
||||
op.drop_index('ix_order_profile_validation_created', table_name='shipping_order_document_profile_validation_runs')
|
||||
op.drop_table('shipping_order_document_profile_validation_runs')
|
||||
@@ -0,0 +1,55 @@
|
||||
"""add order profile publish check reports
|
||||
|
||||
Revision ID: ae0f1a2b3c4d
|
||||
Revises: 9e0f1a2b3c4d
|
||||
Create Date: 2026-07-29 15:00:00.000000
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = 'ae0f1a2b3c4d'
|
||||
down_revision = '9e0f1a2b3c4d'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""创建发布检查报告表,冻结报告、草稿、验证运行及警告确认事实。"""
|
||||
op.create_table(
|
||||
'shipping_order_document_profile_publish_check_reports',
|
||||
sa.Column('id', sa.Integer(), primary_key=True),
|
||||
sa.Column('report_no', sa.String(length=64), nullable=False),
|
||||
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||
sa.Column('revision_no', sa.Integer(), nullable=False),
|
||||
sa.Column('definition_checksum', sa.String(length=64), nullable=False),
|
||||
sa.Column('lock_version', sa.Integer(), nullable=False),
|
||||
sa.Column('validation_run_id', sa.Integer()),
|
||||
sa.Column('base_published_profile_id', sa.Integer()),
|
||||
sa.Column('semantic_diff_json', sa.JSON(), nullable=False),
|
||||
sa.Column('blocking_items_json', sa.JSON(), nullable=False),
|
||||
sa.Column('warning_items_json', sa.JSON(), nullable=False),
|
||||
sa.Column('confirmed_warning_keys_json', sa.JSON(), nullable=False),
|
||||
sa.Column('status', sa.String(length=16), nullable=False),
|
||||
sa.Column('expires_reason', sa.String(length=64)),
|
||||
sa.Column('operation_id', sa.String(length=64), nullable=False),
|
||||
sa.Column('actor_id', sa.Integer()),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('consumed_at', sa.DateTime()),
|
||||
sa.CheckConstraint("status IN ('valid', 'invalidated', 'consumed')", name='ck_sodppcr_status'),
|
||||
sa.UniqueConstraint('profile_id', 'operation_id', name='uq_sodppcr_profile_operation'),
|
||||
sa.ForeignKeyConstraint(['profile_id'], ['shipping_order_document_profiles.id'], ondelete='CASCADE'),
|
||||
sa.ForeignKeyConstraint(['validation_run_id'], ['shipping_order_document_profile_validation_runs.id'], ondelete='SET NULL'),
|
||||
sa.ForeignKeyConstraint(['base_published_profile_id'], ['shipping_order_document_profiles.id'], ondelete='SET NULL'),
|
||||
sa.ForeignKeyConstraint(['actor_id'], ['users.id']),
|
||||
)
|
||||
op.create_index('ix_sodppcr_profile_created', 'shipping_order_document_profile_publish_check_reports', ['profile_id', 'created_at'])
|
||||
op.create_index('ix_sodppcr_report_no', 'shipping_order_document_profile_publish_check_reports', ['report_no'], unique=True)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""移除发布检查报告表。"""
|
||||
op.drop_index('ix_sodppcr_report_no', table_name='shipping_order_document_profile_publish_check_reports')
|
||||
op.drop_index('ix_sodppcr_profile_created', table_name='shipping_order_document_profile_publish_check_reports')
|
||||
op.drop_table('shipping_order_document_profile_publish_check_reports')
|
||||
Reference in new issue
Block a user