70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
const TABLE_NAME = 'wms_print_platform';
|
|
const COLUMN_NAME = 'get_auth_platform_name';
|
|
|
|
/**
|
|
* 判断目标字段是否已存在。
|
|
* @param {Object<string, Object>} columns 字段定义集合。
|
|
* @return {boolean} 字段是否存在。
|
|
*/
|
|
const hasTargetColumn = columns => {
|
|
return Boolean(columns && columns[COLUMN_NAME]);
|
|
};
|
|
|
|
module.exports = {
|
|
/**
|
|
* 正向迁移:为打印平台表新增获取授权平台名称字段(幂等)。
|
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
|
* @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。
|
|
* @return {Promise<void>} 无返回值。
|
|
*/
|
|
async up(queryInterface, Sequelize) {
|
|
const tableNames = await queryInterface.showAllTables();
|
|
const existingTableSet = new Set(
|
|
tableNames.map(table => (typeof table === 'string' ? table : table.tableName))
|
|
);
|
|
|
|
if (!existingTableSet.has(TABLE_NAME)) {
|
|
return;
|
|
}
|
|
|
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
|
if (hasTargetColumn(columns)) {
|
|
return;
|
|
}
|
|
|
|
await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, {
|
|
type: Sequelize.STRING(100),
|
|
allowNull: true,
|
|
comment: '获取授权平台名称',
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 回滚迁移:删除打印平台表的获取授权平台名称字段(幂等)。
|
|
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
|
|
* @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。
|
|
* @return {Promise<void>} 无返回值。
|
|
*/
|
|
async down(queryInterface, Sequelize) {
|
|
void Sequelize;
|
|
|
|
const tableNames = await queryInterface.showAllTables();
|
|
const existingTableSet = new Set(
|
|
tableNames.map(table => (typeof table === 'string' ? table : table.tableName))
|
|
);
|
|
|
|
if (!existingTableSet.has(TABLE_NAME)) {
|
|
return;
|
|
}
|
|
|
|
const columns = await queryInterface.describeTable(TABLE_NAME);
|
|
if (!hasTargetColumn(columns)) {
|
|
return;
|
|
}
|
|
|
|
await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME);
|
|
},
|
|
};
|