74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 为拣货任务表 wms_wave_pick_task 增加领料人字段。
|
||
*
|
||
* 背景:
|
||
* 整波领单(pick.waveClaimScan)会回写订单表 claim_operator_id/claim_operator;
|
||
* 拣货任务创建时需从订单冗余领料人,便于任务列表追溯领料人。
|
||
*
|
||
* 变更:
|
||
* 1. wms_wave_pick_task 新增 claim_operator_id:BIGINT,可空,领料人工号ID。
|
||
* 2. wms_wave_pick_task 新增 claim_operator:VARCHAR(50),可空,领料人姓名。
|
||
*/
|
||
|
||
const TABLE_NAME = 'wms_wave_pick_task';
|
||
|
||
/**
|
||
* 获取表字段定义。
|
||
*
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {string} tableName 表名。
|
||
* @return {Promise<Object>} 字段定义对象。
|
||
*/
|
||
const getTableColumns = async (queryInterface, tableName) => {
|
||
return queryInterface.describeTable(tableName);
|
||
};
|
||
|
||
module.exports = {
|
||
/**
|
||
* 正向迁移:为拣货任务表补充领料人工号与姓名字段。
|
||
*
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
up: async (queryInterface, Sequelize) => {
|
||
const columnsBefore = await getTableColumns(queryInterface, TABLE_NAME);
|
||
|
||
if (!columnsBefore.claim_operator_id) {
|
||
await queryInterface.addColumn(TABLE_NAME, 'claim_operator_id', {
|
||
type: Sequelize.BIGINT,
|
||
allowNull: true,
|
||
comment: '领料人工号ID',
|
||
});
|
||
}
|
||
|
||
if (!columnsBefore.claim_operator) {
|
||
await queryInterface.addColumn(TABLE_NAME, 'claim_operator', {
|
||
type: Sequelize.STRING(50),
|
||
allowNull: true,
|
||
comment: '领料人',
|
||
});
|
||
}
|
||
},
|
||
|
||
/**
|
||
* 回滚迁移:若领料字段存在则删除。
|
||
*
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
||
* @return {Promise<void>} 无返回值。
|
||
*/
|
||
down: async queryInterface => {
|
||
const columnsBefore = await getTableColumns(queryInterface, TABLE_NAME);
|
||
|
||
if (columnsBefore.claim_operator) {
|
||
await queryInterface.removeColumn(TABLE_NAME, 'claim_operator');
|
||
}
|
||
|
||
if (columnsBefore.claim_operator_id) {
|
||
await queryInterface.removeColumn(TABLE_NAME, 'claim_operator_id');
|
||
}
|
||
},
|
||
};
|