63 lines
2.0 KiB
JavaScript
63 lines
2.0 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 将快递接口配置表的 template_id 列从 BIGINT 改为 VARCHAR(50),
|
||
* 以支持快手等平台返回的字符串模板 ID(如 "EBSTO11")。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例
|
||
* @return {Promise<void>} 无返回值
|
||
*/
|
||
module.exports = {
|
||
/**
|
||
* 执行迁移:将 template_id 列类型从 BIGINT 改为 VARCHAR(50)(幂等)。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例
|
||
* @return {Promise<void>} 无返回值
|
||
*/
|
||
async up(queryInterface, Sequelize) {
|
||
const tableName = 'wms_express_interface';
|
||
const columns = await queryInterface.describeTable(tableName);
|
||
|
||
if (!columns.template_id) {
|
||
return;
|
||
}
|
||
|
||
// 如果已经是 VARCHAR 类型则跳过(幂等)
|
||
if (columns.template_id.type && String(columns.template_id.type).toUpperCase().includes('VARCHAR')) {
|
||
return;
|
||
}
|
||
|
||
await queryInterface.changeColumn(tableName, 'template_id', {
|
||
type: Sequelize.STRING(50),
|
||
allowNull: true,
|
||
comment: '模板ID',
|
||
});
|
||
},
|
||
|
||
/**
|
||
* 回滚迁移:将 template_id 列类型从 VARCHAR(50) 改回 BIGINT(幂等)。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||
* @param {import('sequelize')} Sequelize Sequelize 实例
|
||
* @return {Promise<void>} 无返回值
|
||
*/
|
||
async down(queryInterface, Sequelize) {
|
||
const tableName = 'wms_express_interface';
|
||
const columns = await queryInterface.describeTable(tableName);
|
||
|
||
if (!columns.template_id) {
|
||
return;
|
||
}
|
||
|
||
// 如果已经是 BIGINT 类型则跳过(幂等)
|
||
if (columns.template_id.type && String(columns.template_id.type).toUpperCase().includes('BIGINT')) {
|
||
return;
|
||
}
|
||
|
||
await queryInterface.changeColumn(tableName, 'template_id', {
|
||
type: Sequelize.BIGINT.UNSIGNED,
|
||
allowNull: true,
|
||
comment: '模板ID',
|
||
});
|
||
},
|
||
};
|