'use strict'; /** * 获取表字段定义。 * * @param {import('sequelize').QueryInterface} queryInterface 查询接口。 * @param {string} tableName 表名。 * @return {Promise} 字段定义对象。 */ 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} 无返回值。 */ 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} 无返回值。 */ down: async queryInterface => { const tableName = 'wms_wave_pick_task'; const columnsBefore = await getTableColumns(queryInterface, tableName); if (columnsBefore.source) { await queryInterface.removeColumn(tableName, 'source'); } }, };