imaginar/models/chat_message.js

38 lines
876 B
JavaScript
Raw Normal View History

2024-10-19 11:24:54 +00:00
'use strict';
module.exports = (sequelize, DataTypes) => {
const ChatMessage = sequelize.define('ChatMessage', {
id: {
type: DataTypes.BIGINT,
autoIncrement: true,
primaryKey: true
},
user_id: {
type: DataTypes.BIGINT,
allowNull: false
},
isotope_id: {
type: DataTypes.BIGINT,
allowNull: false
},
role: {
type: DataTypes.ENUM('user', 'assistant'),
allowNull: false
},
message: {
type: DataTypes.TEXT,
allowNull: false
}
}, {
tableName: 'chat_messages',
underscored: true,
timestamps: true
});
ChatMessage.associate = function(models) {
ChatMessage.belongsTo(models.User, { foreignKey: 'user_id', onDelete: 'CASCADE' });
ChatMessage.belongsTo(models.Isotope, { foreignKey: 'isotope_id', onDelete: 'CASCADE' });
};
return ChatMessage;
};