'use strict'; /** * 为拣货任务表 wms_wave_pick_task 增加 batch_no_array 字段。 * * 背景: * 一个拣货任务可能涉及多个波次,此前任务主表未冗余波次号, * 统计/查询需要关联 wms_wave_pick_task_wave,不便。 * * 变更: * 1. wms_wave_pick_task 新增 batch_no_array:TEXT,可空, * 存储逗号分隔的波次号列表,如 'WAVE202401001,WAVE202401002', * 便于 FIND_IN_SET / LIKE 等统计与查询。 */ /** * 获取表字段定义。 * * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {string} tableName 表名。 * @return {Promise} 字段定义对象。 */ const getTableColumns = async (queryInterface, tableName) => { return queryInterface.describeTable(tableName); }; module.exports = { /** * 正向迁移:为拣货任务表补充 batch_no_array 字段。 * * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。 * @return {Promise} 无返回值。 */ up: async (queryInterface, Sequelize) => { const tableName = 'wms_wave_pick_task'; const columnsBefore = await getTableColumns(queryInterface, tableName); if (!columnsBefore.batch_no_array) { await queryInterface.addColumn(tableName, 'batch_no_array', { type: Sequelize.TEXT, allowNull: true, comment: '波次号列表(逗号分隔),方便统计和查询', }); } }, /** * 回滚迁移:若 batch_no_array 字段存在则删除。 * * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @return {Promise} 无返回值。 */ down: async queryInterface => { const tableName = 'wms_wave_pick_task'; const columnsBefore = await getTableColumns(queryInterface, tableName); if (columnsBefore.batch_no_array) { await queryInterface.removeColumn(tableName, 'batch_no_array'); } }, };