'use strict'; /** * 发货单(订单)回传平台店铺的同步状态与重试次数: * order_deliveries.shop_sync_status 0未同步 1同步中 2同步成功 3同步失败 * order_deliveries.shop_sync_retry_count 回传失败后的累计重试次数 * * 背景:发货单完成后需要把发货结果(运单号/发货状态)回传平台店铺(shops 表对应的淘宝/抖音等)。 * 此前 OMS 侧只有 `wms_push_result`(JSON,推送 WMS 的结果)与 `pushed_at`(最近一次 WMS 推送时间), * 没有任何「回传平台店铺」的状态列可查(链路尚未实现),故先落字段与状态机基线, * 实际回传(OMS → 平台)后续接入时直接读写这两列即可。 * * 口径来源:app/lib/shopSyncStatus.js(枚举单一来源,前端/服务端共用) * 范围:**只** order_deliveries —— 入库单(inbound_orders)的库存由 OMS 侧自行管理、 * 出库单(outbound_orders)也不涉及平台店铺回传,均不加这两个字段。 * * 幂等:迁移可重复执行(先 describeTable 判断列是否存在)。 */ module.exports = { async up(queryInterface, Sequelize) { const columns = await queryInterface.describeTable('order_deliveries'); if (!columns.shop_sync_status) { await queryInterface.addColumn('order_deliveries', 'shop_sync_status', { type: Sequelize.TINYINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '回传平台店铺状态:0未同步 1同步中 2同步成功 3同步失败', after: 'stock_locked', }); } if (!columns.shop_sync_retry_count) { await queryInterface.addColumn('order_deliveries', 'shop_sync_retry_count', { type: Sequelize.INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '回传平台店铺的重试次数(每次失败后 +1,重试成功不清零以便追溯)', after: 'shop_sync_status', }); } }, async down(queryInterface) { const columns = await queryInterface.describeTable('order_deliveries'); if (columns.shop_sync_retry_count) await queryInterface.removeColumn('order_deliveries', 'shop_sync_retry_count'); if (columns.shop_sync_status) await queryInterface.removeColumn('order_deliveries', 'shop_sync_status'); }, };