WMS_MAIN/database/migrations/20260829160000-add-notify-fields-to-wms-report-delivery.js

78 lines
2.9 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_PLAN = 'wms_report_delivery_plan';
const TABLE_LOG = 'wms_report_delivery_log';
/**
* 报表投递通知能力增强:
* - wms_report_delivery_plan 新增 notify_template(文本通知模板)、
* notify_group_ids(通知群ID数组)、notify_member_ids(通知成员ID数组)
* - wms_report_delivery_log 新增 notify_targets(本次实际投递的群/成员快照,审计回放)
*
* 全部字段可空,不影响存量投递计划与投递记录。
*/
module.exports = {
/**
* 执行迁移:依次新增通知相关字段(幂等:已存在则跳过)。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @param {import('sequelize')} Sequelize Sequelize 实例
* @return {Promise<void>} 无返回值
*/
up: async (queryInterface, Sequelize) => {
const planColumns = await queryInterface.describeTable(TABLE_PLAN);
if (!planColumns.notify_template) {
await queryInterface.addColumn(TABLE_PLAN, 'notify_template', {
type: Sequelize.STRING(500),
allowNull: true,
comment: '文本通知模板,支持 {time}/{url}/{report_name}/{biz_date} 标签',
});
}
if (!planColumns.notify_group_ids) {
await queryInterface.addColumn(TABLE_PLAN, 'notify_group_ids', {
type: Sequelize.JSON,
allowNull: true,
comment: '通知群ID数组(wms_inbox_group.id,多选;空=不指定群)',
});
}
if (!planColumns.notify_member_ids) {
await queryInterface.addColumn(TABLE_PLAN, 'notify_member_ids', {
type: Sequelize.JSON,
allowNull: true,
comment: '通知成员ID数组(外部IM用户ID,多选;目标侧支持数组)',
});
}
const logColumns = await queryInterface.describeTable(TABLE_LOG);
if (!logColumns.notify_targets) {
await queryInterface.addColumn(TABLE_LOG, 'notify_targets', {
type: Sequelize.JSON,
allowNull: true,
comment: '投递目标快照:{group_ids:[],member_ids:[]}(本次实际发送的群/成员,审计回放)',
});
}
},
/**
* 回滚迁移:按新增顺序的逆序删除字段(幂等:不存在则跳过)。
* @param {import('sequelize').QueryInterface} queryInterface 查询接口
* @return {Promise<void>} 无返回值
*/
down: async queryInterface => {
const planColumns = await queryInterface.describeTable(TABLE_PLAN);
if (planColumns.notify_member_ids) {
await queryInterface.removeColumn(TABLE_PLAN, 'notify_member_ids');
}
if (planColumns.notify_group_ids) {
await queryInterface.removeColumn(TABLE_PLAN, 'notify_group_ids');
}
if (planColumns.notify_template) {
await queryInterface.removeColumn(TABLE_PLAN, 'notify_template');
}
const logColumns = await queryInterface.describeTable(TABLE_LOG);
if (logColumns.notify_targets) {
await queryInterface.removeColumn(TABLE_LOG, 'notify_targets');
}
},
};