WMS_MAIN/database/migrations/20260606000000-change-template-id-to-varchar-wms-express-interface.js
liufumingren eb100b056d 1
2026-06-07 01:52:06 +08:00

63 lines
2.0 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';
/**
* 将快递接口配置表的 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',
});
},
};