'use strict'; /** 邮件发送日志表:记录收件邮箱、正文、关联账号(注册场景为空)、IP 与发送结果 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'email_logs', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true, }, scene: { type: Sequelize.STRING(30), allowNull: false, defaultValue: 'register', comment: '业务场景:register 等' }, to_email: { type: Sequelize.STRING(100), allowNull: false, comment: '收件邮箱' }, subject: { type: Sequelize.STRING(200), allowNull: true, comment: '邮件标题' }, content: { type: Sequelize.TEXT, allowNull: true, comment: '邮件正文' }, user_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '关联用户ID,注册场景为空' }, ip: { type: Sequelize.STRING(45), allowNull: true, comment: '请求方IP' }, status: { type: Sequelize.TINYINT, allowNull: false, defaultValue: 0, comment: '发送状态:1成功 0失败' }, error_msg: { type: Sequelize.STRING(500), allowNull: true, comment: '失败原因' }, created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), }, updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), }, }, { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '邮件发送日志表' } ); await queryInterface.addIndex('email_logs', { fields: [ 'to_email' ], name: 'idx_email_logs_to_email' }); await queryInterface.addIndex('email_logs', { fields: [ 'created_at' ], name: 'idx_email_logs_created_at' }); }, async down(queryInterface) { await queryInterface.dropTable('email_logs'); }, };