57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
'use strict';
|
||
|
||
const TABLE_PLAN = 'wms_report_delivery_plan';
|
||
|
||
/**
|
||
* 为报表投递计划表新增计划名称字段 name。
|
||
*
|
||
* 背景:报表投递计划在管理端列表/详情展示时需要展示计划名称(前端展示用),
|
||
* 因此为 wms_report_delivery_plan 新增 name 列,按规格位于 report_definition_id 之后。
|
||
*
|
||
* 全部存量计划允许 name 为空(可空列),不影响既有投递计划与投递逻辑。
|
||
*/
|
||
module.exports = {
|
||
/**
|
||
* 执行迁移:新增 name 列(幂等:已存在则跳过)。
|
||
*
|
||
* 说明:sequelize 的 addColumn 不支持指定列位置(AFTER),
|
||
* 为满足「位于 report_definition_id 之后」的规格要求,
|
||
* 使用原生 DDL 控制列位置,与项目既有迁移
|
||
* (restructure-report-definition-by-id)的做法一致。
|
||
*
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||
* @return {Promise<void>} 无返回值
|
||
*/
|
||
async up(queryInterface) {
|
||
const { sequelize } = queryInterface;
|
||
const columns = await queryInterface.describeTable(TABLE_PLAN);
|
||
|
||
// 幂等保护:已存在 name 列时跳过
|
||
if (columns.name) {
|
||
return;
|
||
}
|
||
|
||
await sequelize.query(
|
||
`ALTER TABLE \`${TABLE_PLAN}\`
|
||
ADD COLUMN \`name\` VARCHAR(100) NULL COMMENT '计划名称(前端展示用)'
|
||
AFTER \`report_definition_id\``
|
||
);
|
||
},
|
||
|
||
/**
|
||
* 回滚迁移:删除 name 列(幂等:不存在则跳过)。
|
||
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
|
||
* @return {Promise<void>} 无返回值
|
||
*/
|
||
async down(queryInterface) {
|
||
const columns = await queryInterface.describeTable(TABLE_PLAN);
|
||
|
||
// 幂等保护:不存在 name 列时跳过
|
||
if (!columns.name) {
|
||
return;
|
||
}
|
||
|
||
await queryInterface.removeColumn(TABLE_PLAN, 'name');
|
||
},
|
||
};
|