'use strict'; const TABLE_PLAN = 'wms_report_delivery_plan'; const TABLE_LOG = 'wms_report_delivery_log'; /** * 报表投递渠道收敛为 inbox(wecom/link 已弃用)。 * * - wms_report_delivery_plan.channel:默认值 wecom → inbox,comment 收敛 * - wms_report_delivery_log.channel:默认值 wecom → inbox,comment 收敛 * - 存量数据归一化:channel IN ('wecom','link') 的行统一更新为 'inbox' * * down 仅回退列默认值与 comment;数据 UPDATE 不回退(历史行无法还原原渠道)。 */ module.exports = { async up(queryInterface, Sequelize) { // 1. 计划表:默认值 + comment 收敛 await queryInterface.changeColumn(TABLE_PLAN, 'channel', { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'inbox', comment: '投递渠道:inbox=站内信群(wecom/link 已弃用)', }); await queryInterface.sequelize.query( `UPDATE ${TABLE_PLAN} SET channel = 'inbox' WHERE channel IN ('wecom', 'link')` ); // 2. 记录表:默认值 + comment 收敛 await queryInterface.changeColumn(TABLE_LOG, 'channel', { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'inbox', comment: '投递渠道快照:inbox=站内信群(wecom/link 已弃用)', }); await queryInterface.sequelize.query( `UPDATE ${TABLE_LOG} SET channel = 'inbox' WHERE channel IN ('wecom', 'link')` ); }, async down(queryInterface, Sequelize) { // 仅回退默认值与 comment;存量数据不回退(已归一化为 inbox 的行无法还原原渠道) await queryInterface.changeColumn(TABLE_PLAN, 'channel', { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'wecom', comment: '投递渠道:wecom=企业微信 inbox=站内信群 link=链接', }); await queryInterface.changeColumn(TABLE_LOG, 'channel', { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'wecom', comment: '投递渠道快照:wecom=企业微信 inbox=站内信群 link=链接', }); }, };