WMS_MAIN/database/migrations/20260525143000-drop-platform-code-from-wms-platform.js
liufumingren abf2c4d94a 1
2026-05-29 16:47:38 +08:00

62 lines
1.8 KiB
JavaScript

'use strict';
const TABLE_NAME = 'wms_platform';
const COLUMN_NAME = 'platform_code';
/**
* 获取当前数据库已存在的表名集合。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<Set<string>>} 表名集合。
*/
const getExistingTableSet = async queryInterface => {
const tables = await queryInterface.showAllTables();
return new Set(
tables.map(table => (typeof table === 'string' ? table : table.tableName))
);
};
module.exports = {
/**
* 正向迁移:幂等删除 wms_platform.platform_code。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
async up(queryInterface) {
const existingTables = await getExistingTableSet(queryInterface);
if (!existingTables.has(TABLE_NAME)) {
return;
}
const columns = await queryInterface.describeTable(TABLE_NAME);
if (!columns[COLUMN_NAME]) {
return;
}
await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME);
},
/**
* 回滚迁移:幂等恢复 wms_platform.platform_code。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。
* @return {Promise<void>} 无返回值。
*/
async down(queryInterface, Sequelize) {
const existingTables = await getExistingTableSet(queryInterface);
if (!existingTables.has(TABLE_NAME)) {
return;
}
const columns = await queryInterface.describeTable(TABLE_NAME);
if (columns[COLUMN_NAME]) {
return;
}
await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, {
type: Sequelize.STRING(255),
allowNull: true,
comment: '平台编码',
});
},
};