WMS_MAIN/database/migrations/20260904120000-add-batch-no-array-to-wms-wave-pick-task.js

63 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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<Object>} 字段定义对象。
*/
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<void>} 无返回值。
*/
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<void>} 无返回值。
*/
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');
}
},
};