fix(inventory-candidate-freeze): 修正库存候选冻结迁移的依赖声明并添加验证测试

扩展迁移脚本的down_revision为包含两个必要的revision链,新增测试用例验证候选冻结迁移必须同时依赖Notice与订单履约的迁移版本,避免单独依赖单个版本导致父表缺失。
This commit is contained in:
hugo committed 2026-08-13 18:33:13 +08:00
1 parent b60be6bc20
commit af8c39f652
2 files changed
+23 -2

No files matched your search

@@ -9,7 +9,7 @@ migrations/versions/cp1a2b3c4d5e_add_inventory_candidate_freeze_tables.py
作为不可变审计副本。
依赖:shipping_notices、shipping_order_review_cases、shipping_process_executions、
users、shipping_inventory_routing_rules(外键均为 SET NULL / CASCADE,不破坏历史)。
逻辑:Revises dc9a4a2683df_merge_heads;
逻辑:Revises dc9a4a2683df_merge_heads 与 co9f0a1b2c3d(Notice/订单履约链);
新增表 + 唯一索引 + 部分唯一索引(PostgreSQL WHERE 条件);
不修改任何已有表字段,纯新增不破坏历史数据。
@@ -25,7 +25,7 @@ from alembic import op
revision = 'cp1a2b3c4d5e'
down_revision = 'dc9a4a2683df'
down_revision = ('dc9a4a2683df', 'co9f0a1b2c3d')
branch_labels = None
depends_on = None
@@ -0,0 +1,21 @@
"""
backend/tests/test_inventory_candidate_freeze_migration_revision.py
用途:验证库存候选冻结迁移的父 revision 同时覆盖正式 Notice 与候选冻结依赖链。
依赖:cp1a2b3c4d5e 迁移模块。
逻辑:候选冻结表声明引用 shipping_notices、review/process/routing 表,必须在包含
co9f0a1b2c3d 祖先链的数据库状态上执行;单独依赖 dc9a4a2683df 会导致父表缺失。
"""
from __future__ import annotations
import importlib
def test_candidate_freeze_migration_depends_on_notice_schema_chain():
"""关键断言:候选冻结迁移必须等待 dc9 merge 与 Notice 迁移链共同完成。"""
migration = importlib.import_module(
'migrations.versions.cp1a2b3c4d5e_add_inventory_candidate_freeze_tables',
)
assert set(migration.down_revision) == {'dc9a4a2683df', 'co9f0a1b2c3d'}