const Sequelize = require('sequelize'); /** * 聊天消息表 * 每句话一条记录;会话形态(仅 data+job)用 mid=0 存一条 */ module.exports = (db) => { const chat_message = db.define('chat_message', { sn_code: { comment: '设备SN码', type: Sequelize.STRING(50), allowNull: false, defaultValue: '' }, platform: { comment: '平台: boss / liepin', type: Sequelize.STRING(20), allowNull: false, defaultValue: 'boss' }, friendId: { comment: '好友/会话ID', type: Sequelize.BIGINT, allowNull: false }, encryptFriendId: { comment: '好友加密ID', type: Sequelize.STRING(100), allowNull: true, defaultValue: '' }, mid: { comment: '消息ID(接口返回)', type: Sequelize.BIGINT, allowNull: false }, message_data: { comment: '单条消息原始数据 JSON', type: Sequelize.JSON, allowNull: true, defaultValue: null }, fetch_time: { comment: '拉取时间', type: Sequelize.DATE, allowNull: true, defaultValue: Sequelize.NOW } }, { timestamps: false, indexes: [ { unique: true, fields: ['sn_code', 'platform', 'friendId', 'mid'] }, { unique: false, fields: ['sn_code', 'platform', 'friendId'] }, { unique: false, fields: ['fetch_time'] } ] }); // chat_message.sync({ force: true }); return chat_message; };