'use strict'; /** * 打包任务表 wms_pack_task 增加 wave_scope(波次范围)字段。 * * 取值约定(与 wms_order_delivery.wave_scope 一致): * - 0 = 未分配波次 * - 1 = 大团购 * - 2 = 散单 * - 3 = 小团购 * - 4 = 单品单件 * 默认 0。 * * 来源:workbench.packOrder 创建打包任务时落库,值由服务端复查 * (优先取打包上下文上报值,非法/缺省时兜底取订单行 wave_scope)。 * * 幂等:列已存在则跳过。 */ const TABLE_NAME = 'wms_pack_task'; const COLUMN_NAME = 'wave_scope'; /** * 判断列是否已存在。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {string} tableName 表名。 * @param {string} columnName 列名。 * @return {Promise} 是否存在。 */ async function columnExists(queryInterface, tableName, columnName) { const described = await queryInterface.describeTable(tableName); return Boolean(described && described[columnName]); } module.exports = { /** * 执行迁移:为 wms_pack_task 增加 wave_scope 列。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {import('sequelize')} Sequelize Sequelize 构造器。 * @return {Promise} 无返回值。 */ async up(queryInterface, Sequelize) { if (await columnExists(queryInterface, TABLE_NAME, COLUMN_NAME)) { console.log('[20260924150000-add-wave-scope-to-pack-task] up: 列已存在,跳过'); return; } await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, { type: Sequelize.TINYINT(4), allowNull: false, defaultValue: 0, comment: '波次范围:0未分配波次 1大团购 2散单 3小团购 4单品单件', }); console.log('[20260924150000-add-wave-scope-to-pack-task] up: 已为 wms_pack_task 添加 wave_scope 列'); }, /** * 回滚迁移:移除 wms_pack_task 的 wave_scope 列。 * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @return {Promise} 无返回值。 */ async down(queryInterface) { if (!await columnExists(queryInterface, TABLE_NAME, COLUMN_NAME)) { console.log('[20260924150000-add-wave-scope-to-pack-task] down: 列不存在,跳过'); return; } await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME); console.log('[20260924150000-add-wave-scope-to-pack-task] down: 已移除 wms_pack_task 的 wave_scope 列'); }, };