WMS_MAIN/database/migrations/20260904130000-add-claim-operator-to-wms-wave-batch.js

75 lines
2.3 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_batch 增加领料人字段。
*
* 背景:
* 整波领单(pick.waveClaimScan)是波次级操作,此前仅写入订单操作日志
* (ORDER_WAVE_CLAIM),波次表无领料人记录,不便于核对领料人与领料时间。
*
* 变更:
* 1. wms_wave_batch 新增 claim_operator:VARCHAR(50),可空,领料人姓名。
* 2. wms_wave_batch 新增 claim_time:DATETIME,可空,领料时间。
* 3. 模型定义同步更新(app/model/wave_batch.js)。
*/
const TABLE_NAME = 'wms_wave_batch';
/**
* 获取表字段定义。
*
* @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) {
await queryInterface.addColumn(TABLE_NAME, 'claim_operator', {
type: Sequelize.STRING(50),
allowNull: true,
comment: '领料人',
});
}
if (!columnsBefore.claim_time) {
await queryInterface.addColumn(TABLE_NAME, 'claim_time', {
type: Sequelize.DATE,
allowNull: true,
comment: '领料时间',
});
}
},
/**
* 回滚迁移:若领料字段存在则删除。
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
down: async queryInterface => {
const columnsBefore = await getTableColumns(queryInterface, TABLE_NAME);
if (columnsBefore.claim_time) {
await queryInterface.removeColumn(TABLE_NAME, 'claim_time');
}
if (columnsBefore.claim_operator) {
await queryInterface.removeColumn(TABLE_NAME, 'claim_operator');
}
},
};