rwadurian/backend/services/contribution-service/prisma/pre-planting/migrations
hailin 390e5ccb19 fix(pre-planting): 用 orderNo 替代 BigInt 自增 ID 作为 CDC 关联键
问题:Debezium CDC 事件中 Prisma @map("order_id") 字段以 DB 列名
order_id 发送,而代码访问 data.id 导致 undefined → BigInt 转换失败。

修复方案(遵循"用 orderNo 业务键关联"原则):
- pre-planting-order-synced.handler.ts:
  * PrePlantingOrderSyncResult 改为 { orderNo: string }
  * handleCreateOrSnapshot/handleUpdate 均用 order_no 字段
  * syncToTrackingTable upsert where 改为 { orderNo }
  * ensureAdoptionMarker 入参从 orderId bigint 改为 orderNo string
    - markerAdoptionId = PRE_PLANTING_SOURCE_ID_OFFSET + hash(orderNo)
  * isAlreadyDistributed 改为 findUnique({ where: { orderNo } })
  * calculateAfterCommit 传 result.orderNo
- pre-planting-contribution.service.ts:
  * calculateForPrePlantingOrder 入参从 bigint 改为 string(orderNo)
  * findUnique({ where: { orderNo } }) 查询,用存储的 originalOrderId 计算偏移
  * 所有日志/update 中 originalOrderId 替换为 orderNo
  * processUndistributedOrders 改为传 order.orderNo,orderBy 改为 createdAt
- schema.prisma:orderNo 字段新增 @unique 约束
- migration SQL:CREATE UNIQUE INDEX on order_no 列

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 02:31:04 -08:00
..
20260223000000_init_pre_planting fix(pre-planting): 修复 5 个预种模块 Bug + 补全 3 服务 migration 2026-02-23 18:09:14 -08:00
20260228000000_add_unique_order_no_to_synced_orders fix(pre-planting): 用 orderNo 替代 BigInt 自增 ID 作为 CDC 关联键 2026-02-28 02:31:04 -08:00
migration_lock.toml fix(pre-planting): 修复 5 个预种模块 Bug + 补全 3 服务 migration 2026-02-23 18:09:14 -08:00