WMS_MAIN/database/migrations/20260508150000-add-source-to-wave-pick-task.js
liufumingren 9c2b254206 1
Co-authored-by: Copilot <copilot@github.com>
2026-05-11 08:44:27 +08:00

51 lines
1.5 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';
/**
* 获取表字段定义。
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {string} tableName 表名。
* @return {Promise<Object>} 字段定义对象。
*/
const getTableColumns = async (queryInterface, tableName) => {
return queryInterface.describeTable(tableName);
};
module.exports = {
/**
* 正向迁移:为拣货任务表补充 source 字段。
*
* @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.source) {
await queryInterface.addColumn(tableName, 'source', {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 1,
comment: '任务来源:1-PDA 2-后台',
});
}
},
/**
* 回滚迁移:若 source 字段存在则删除。
*
* @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.source) {
await queryInterface.removeColumn(tableName, 'source');
}
},
};