diff --git a/apps/backend/src/db/migrations/122_fulfillment_routing_invariants.sql b/apps/backend/src/db/migrations/120_fulfillment_routing_invariants.sql similarity index 99% rename from apps/backend/src/db/migrations/122_fulfillment_routing_invariants.sql rename to apps/backend/src/db/migrations/120_fulfillment_routing_invariants.sql index 6de9dd60..dcb4e86e 100644 --- a/apps/backend/src/db/migrations/122_fulfillment_routing_invariants.sql +++ b/apps/backend/src/db/migrations/120_fulfillment_routing_invariants.sql @@ -1,6 +1,6 @@ --- 122_fulfillment_routing_invariants.sql +-- 120_fulfillment_routing_invariants.sql -- --- 合并 main 后的履约路由统一迁移(接在 dev 120/121 之后)。 +-- 生产迁移 119 之后的履约路由统一迁移。 -- -- 目标: -- 1. 订单项内部 SKU 只有一个 SQL 解析口径; diff --git a/apps/backend/src/db/migrations/123_internal_sku_single_primary.sql b/apps/backend/src/db/migrations/121_internal_sku_single_primary.sql similarity index 90% rename from apps/backend/src/db/migrations/123_internal_sku_single_primary.sql rename to apps/backend/src/db/migrations/121_internal_sku_single_primary.sql index ae22b493..cb17f55f 100644 --- a/apps/backend/src/db/migrations/123_internal_sku_single_primary.sql +++ b/apps/backend/src/db/migrations/121_internal_sku_single_primary.sql @@ -1,7 +1,7 @@ --- 123_internal_sku_single_primary.sql +-- 121_internal_sku_single_primary.sql -- -- 一个内部 SKU 只能有一个主渠道;其他渠道必须显式标记 is_fallback。 --- 迁移 122 已把人工并列渠道收敛为兜底;这里在任何剩余歧义上显式阻止部署。 +-- 迁移 120 已把人工并列渠道收敛为兜底;这里在任何剩余歧义上显式阻止部署。 DO $$ DECLARE diff --git a/apps/backend/src/db/migrations/124_work_order_template_product_projection.sql b/apps/backend/src/db/migrations/122_work_order_template_product_projection.sql similarity index 97% rename from apps/backend/src/db/migrations/124_work_order_template_product_projection.sql rename to apps/backend/src/db/migrations/122_work_order_template_product_projection.sql index b0b2bcb1..5c32f360 100644 --- a/apps/backend/src/db/migrations/124_work_order_template_product_projection.sql +++ b/apps/backend/src/db/migrations/122_work_order_template_product_projection.sql @@ -1,4 +1,4 @@ --- 124_work_order_template_product_projection.sql +-- 122_work_order_template_product_projection.sql -- 接单模板商品改为事件驱动投影:新模板保存时自动建/更新商品。 -- 本迁移补齐现有模板商品,并统一状态、名称、分类和价格属性。 diff --git a/apps/backend/src/db/migrations/125_work_product_rule_pricing_mode.sql b/apps/backend/src/db/migrations/123_work_product_rule_pricing_mode.sql similarity index 97% rename from apps/backend/src/db/migrations/125_work_product_rule_pricing_mode.sql rename to apps/backend/src/db/migrations/123_work_product_rule_pricing_mode.sql index ff3d004d..97064401 100644 --- a/apps/backend/src/db/migrations/125_work_product_rule_pricing_mode.sql +++ b/apps/backend/src/db/migrations/123_work_product_rule_pricing_mode.sql @@ -1,4 +1,4 @@ --- 125_work_product_rule_pricing_mode.sql +-- 123_work_product_rule_pricing_mode.sql -- 接单模板显式保存计价方式,金额字段只由商品与成本中心写投影。 -- 历史数据按旧运行口径回填:拼单自动按件优先识别,其次识别“单价>0 且固定金额=0”。 diff --git a/apps/backend/src/db/migrations/120_work_order_user_payment_amount_audit.sql b/apps/backend/src/db/migrations/124_work_order_user_payment_amount_audit.sql similarity index 94% rename from apps/backend/src/db/migrations/120_work_order_user_payment_amount_audit.sql rename to apps/backend/src/db/migrations/124_work_order_user_payment_amount_audit.sql index d37143e4..65b80932 100644 --- a/apps/backend/src/db/migrations/120_work_order_user_payment_amount_audit.sql +++ b/apps/backend/src/db/migrations/124_work_order_user_payment_amount_audit.sql @@ -1,4 +1,4 @@ --- 120_work_order_user_payment_amount_audit.sql +-- 124_work_order_user_payment_amount_audit.sql -- 工单「用户付款金额」最近一次修正快照:旧价、修改时间、修改人。 -- 完整修改历史仍在 work_order_events.payment_amount_updated。 diff --git a/apps/backend/src/db/migrations/121_work_order_payment_amount_history.sql b/apps/backend/src/db/migrations/125_work_order_payment_amount_history.sql similarity index 98% rename from apps/backend/src/db/migrations/121_work_order_payment_amount_history.sql rename to apps/backend/src/db/migrations/125_work_order_payment_amount_history.sql index c7128a77..fa04c6b4 100644 --- a/apps/backend/src/db/migrations/121_work_order_payment_amount_history.sql +++ b/apps/backend/src/db/migrations/125_work_order_payment_amount_history.sql @@ -1,4 +1,4 @@ --- 121_work_order_payment_amount_history.sql +-- 125_work_order_payment_amount_history.sql -- 工单「用户付款金额」完整修改历史:每次修改一行。 -- 独立于 work_order_events(默认只保留 180 天),工单删除时级联删除。 diff --git a/apps/backend/src/services/worker-platform/work-order-payment-history.test.ts b/apps/backend/src/services/worker-platform/work-order-payment-history.test.ts index 536ad9c7..6eb8f963 100644 --- a/apps/backend/src/services/worker-platform/work-order-payment-history.test.ts +++ b/apps/backend/src/services/worker-platform/work-order-payment-history.test.ts @@ -7,7 +7,7 @@ function read(relativeUrl: string) { } test('价格历史迁移建表、建索引并回填 payment_amount_updated 事件', async () => { - const sql = await read('../../db/migrations/121_work_order_payment_amount_history.sql') + const sql = await read('../../db/migrations/125_work_order_payment_amount_history.sql') assert.ok(sql.includes('CREATE TABLE IF NOT EXISTS work_order_payment_amount_history')) assert.ok(sql.includes('idx_work_order_payment_amount_history_order')) assert.ok(sql.includes("e.event_type = 'payment_amount_updated'")) diff --git a/docs/生产部署核对清单-2026-11-02.md b/docs/生产部署核对清单-2026-11-02.md index 0d95ed69..0d101925 100644 --- a/docs/生产部署核对清单-2026-11-02.md +++ b/docs/生产部署核对清单-2026-11-02.md @@ -1,7 +1,7 @@ # 生产部署核对清单(履约与财务分流统一) 日期:2026-11-02 -适用:生产当前在迁移 115,本次新增 116–125 + backend/frontend。 +适用:生产已应用 116–123(main 合并的履约路由 120–123 已先行上线),本次新增 124–125(工单付款金额审计与价格历史)+ backend/frontend。 ## 1. 部署前 @@ -24,25 +24,31 @@ 117_internal_sku_mappings 118_internal_sku_channels 119_fulfillment_pending_reason -120_work_order_user_payment_amount_audit -121_work_order_payment_amount_history -122_fulfillment_routing_invariants -123_internal_sku_single_primary -124_work_order_template_product_projection -125_work_product_rule_pricing_mode +120_fulfillment_routing_invariants +121_internal_sku_single_primary +122_work_order_template_product_projection +123_work_product_rule_pricing_mode +124_work_order_user_payment_amount_audit +125_work_order_payment_amount_history ``` +> 序号说明:生产在合并 main 后已按 120–123 应用了履约路由四支迁移,因此这四支编号固定不变; +> dev 分支的付款金额审计与价格历史顺延为 124、125,避免 `node-pg-migrate` 的 `checkOrder` 报 +> `Not run migration ... is preceding already run migration ...`。 + 重点检查: - 116:给已有 `tpv:` 商品补 capability 和 internal_sku 规则; - 118:按商品能力/规则回填 `internal_sku_channels`; - SQL 已做聚合,避免同名商品同渠道 `ON CONFLICT` 二次更新报错; - 119:只加列和索引,风险低。 -- 122:建立统一内部 SKU SQL 函数、回填人工配置、迁移可确定的旧 sku_code 规则。 -- 123:建立唯一主渠道索引;若仍有并列主渠道会主动阻断迁移。 -- 124:按接单模板补齐/刷新 `tpl:` 商品,只做 UPSERT,不删除商品、成本、订单或工单。 -- 125:接单模板增加计价方式并回填历史模板,金额字段继续只由商品与成本中心投影。 -- SQL 护栏默认只保护到生产已发布的迁移 119;部署 122 后应把 `PUBLISHED_MIGRATION_MAX_VERSION` 提升为 122。 +- 120:建立统一内部 SKU SQL 函数、回填人工配置、迁移可确定的旧 sku_code 规则。 +- 121:建立唯一主渠道索引;若仍有并列主渠道会主动阻断迁移。 +- 122:按接单模板补齐/刷新 `tpl:` 商品,只做 UPSERT,不删除商品、成本、订单或工单。 +- 123:接单模板增加计价方式并回填历史模板,金额字段继续只由商品与成本中心投影。 +- 124:`work_orders` 增加付款金额旧价、修改时间、修改人三列(`ADD COLUMN IF NOT EXISTS`),幂等且不动存量数据。 +- 125:新建 `work_order_payment_amount_history` 并回填已有 `payment_amount_updated` 事件,写入按工单级联删除。 +- SQL 护栏默认只保护到生产已发布的迁移 119;部署 120 后应把 `PUBLISHED_MIGRATION_MAX_VERSION` 提升为 120。 ## 3. 部署顺序 @@ -169,4 +175,4 @@ npx tsx scripts/reclassify-post-cutover.ts --apply - 数据库: - 116–125 均为新增表/列/函数/投影数据,不删旧表,可保留; - 若必须回滚,恢复到部署前备份; -- 迁移 118–123 不改旧字段语义,回滚代码后旧逻辑仍可运行;123 的唯一主渠道索引会阻止旧代码写入并列主渠道。 +- 迁移 118–121 不改旧字段语义,回滚代码后旧逻辑仍可运行;121 的唯一主渠道索引会阻止旧代码写入并列主渠道。