WMS_MAIN/database/migrations/archive/20260415172000-create-wms-express-interface.js

75 lines
1.9 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
const { INTEGER, STRING } = Sequelize;
const [ tables ] = await queryInterface.sequelize.query(
"SHOW TABLES LIKE 'wms_express_interface'"
);
if (tables.length > 0) {
console.log('Table wms_express_interface already exists, skipping creation');
return;
}
await queryInterface.createTable('wms_express_interface', {
id: {
type: INTEGER(10),
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '接口ID',
},
interface_url: {
type: STRING(500),
allowNull: false,
comment: '外部接口URL',
},
platform_code: {
type: STRING(50),
allowNull: false,
comment: '平台代码,用于应用分流',
},
interface_name: {
type: STRING(200),
allowNull: false,
comment: '接口名称',
},
}, {
engine: 'InnoDB',
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
comment: '快递外部接口配置表',
});
const safeCreateIndex = async (tableName, fields, options) => {
const [ existingIndexes ] = await queryInterface.sequelize.query(
`SHOW INDEX FROM ${tableName} WHERE Key_name = '${options.name}'`
);
if (existingIndexes.length === 0) {
await queryInterface.addIndex(tableName, fields, options);
}
};
await safeCreateIndex('wms_express_interface', [ 'platform_code' ], {
name: 'idx_platform_code',
});
await safeCreateIndex('wms_express_interface', [ 'interface_name' ], {
name: 'idx_interface_name',
});
},
async down(queryInterface) {
const [ tables ] = await queryInterface.sequelize.query(
"SHOW TABLES LIKE 'wms_express_interface'"
);
if (tables.length > 0) {
await queryInterface.dropTable('wms_express_interface');
}
},
};