WMS_MAIN/database/migrations/20260526100000-add-need-callback-url-to-wms-print-platform.js
liufumingren abf2c4d94a 1
2026-05-29 16:47:38 +08:00

70 lines
2.1 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';
const TABLE_NAME = 'wms_print_platform';
const COLUMN_NAME = 'need_callback_url';
/**
* 获取当前数据库已存在的表名集合。
* @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))
);
};
/**
* 构建打印平台是否需要回调地址字段定义。
* @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。
* @return {Object} 字段定义。
*/
const buildNeedCallbackUrlColumn = Sequelize => ({
type: Sequelize.TINYINT(1),
allowNull: false,
defaultValue: 1,
comment: '是否需要回调地址:0-否,1-是',
});
module.exports = {
/**
* 执行迁移:为打印平台表新增 need_callback_url 字段。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @param {typeof import('sequelize')} Sequelize Sequelize 类型集合。
* @return {Promise<void>} 无返回值。
*/
async up(queryInterface, Sequelize) {
const existingTableSet = await getExistingTableSet(queryInterface);
if (!existingTableSet.has(TABLE_NAME)) {
return;
}
const columns = await queryInterface.describeTable(TABLE_NAME);
if (columns[COLUMN_NAME]) {
return;
}
await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, buildNeedCallbackUrlColumn(Sequelize));
},
/**
* 回滚迁移:删除打印平台表的 need_callback_url 字段。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口。
* @return {Promise<void>} 无返回值。
*/
async down(queryInterface) {
const existingTableSet = await getExistingTableSet(queryInterface);
if (!existingTableSet.has(TABLE_NAME)) {
return;
}
const columns = await queryInterface.describeTable(TABLE_NAME);
if (!columns[COLUMN_NAME]) {
return;
}
await queryInterface.removeColumn(TABLE_NAME, COLUMN_NAME);
},
};