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

57 lines
1.7 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 字段。
*
* 字段语义:0-普通波次 1-管理后台策略任务 2-PDA策略任务
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
up: async queryInterface => {
const tableName = 'wms_wave_batch';
const columnsBefore = await getTableColumns(queryInterface, tableName);
if (!columnsBefore.source) {
await queryInterface.sequelize.query(`
ALTER TABLE wms_wave_batch
ADD COLUMN source TINYINT NOT NULL DEFAULT 0
COMMENT '来源:0-普通波次 1-管理后台策略任务 2-PDA策略任务'
AFTER update_time
`);
}
const columnsAfter = await getTableColumns(queryInterface, tableName);
if (!columnsAfter.source) {
throw new Error('迁移失败:wms_wave_batch.source 字段不存在');
}
},
/**
* 回滚迁移:删除波次表 source 字段。
*
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
down: async queryInterface => {
const tableName = 'wms_wave_batch';
const columnsBefore = await getTableColumns(queryInterface, tableName);
if (columnsBefore.source) {
await queryInterface.removeColumn(tableName, 'source');
}
},
};