'use strict'; /** * 多运单号留存:outbound_orders.express_codes / order_deliveries.express_codes(JSON 数组) * * 背景:WMS 出库确认(stockout.confirm)与发货确认(deliveryorder.confirm)的报文中 * `packages.package` 是**数组**(一单可拆多个包裹、每个包裹一个运单号,如 CK_4 一单两个运单号)。 * 但 OMS 侧 order_deliveries.express_code 是单值列(只落第一个运单号),outbound_orders 更是没有运单号列, * 多运单只能翻 wms_push_result.confirm.packages[] 的 JSON,无法在列表/筛选/导出/对外接口里用。 * 故两表各加一个 express_codes(JSON 数组)留存全部运单号;单值字段(express_code)保留, * 继续表示「首个运单号」,兼容既有口径与前端展示。 * * 幂等:迁移可重复执行(先 describeTable 判断列是否存在)。 */ module.exports = { async up(queryInterface, Sequelize) { const outboundColumns = await queryInterface.describeTable('outbound_orders'); if (!outboundColumns.express_codes) { await queryInterface.addColumn('outbound_orders', 'express_codes', { type: Sequelize.JSON, allowNull: true, comment: '运单号集合(WMS 出库确认 packages.package[].expressCode,多包裹时为数组)', after: 'stock_deducted', }); } const deliveryColumns = await queryInterface.describeTable('order_deliveries'); if (!deliveryColumns.express_codes) { await queryInterface.addColumn('order_deliveries', 'express_codes', { type: Sequelize.JSON, allowNull: true, comment: '运单号集合(WMS 发货确认 packages.package[].expressCode,多包裹时为数组)', after: 'express_code', }); } }, async down(queryInterface) { const outboundColumns = await queryInterface.describeTable('outbound_orders'); if (outboundColumns.express_codes) await queryInterface.removeColumn('outbound_orders', 'express_codes'); const deliveryColumns = await queryInterface.describeTable('order_deliveries'); if (deliveryColumns.express_codes) await queryInterface.removeColumn('order_deliveries', 'express_codes'); }, };