const { DataTypes } = require('sequelize'); module.exports = { up: async (queryInterface, Sequelize) => { await queryInterface.createTable('messages', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, allowNull: false }, conversation_id: { type: DataTypes.UUID, allowNull: false, references: { model: 'conversations', key: 'id' }, onUpdate: 'CASCADE', onDelete: 'CASCADE' }, plan_id: { type: DataTypes.UUID, allowNull: true, references: { model: 'plans', key: 'id' }, onUpdate: 'CASCADE', onDelete: 'SET NULL' }, role: { type: DataTypes.ENUM('user', 'assistant', 'system'), allowNull: false }, content: { type: DataTypes.TEXT, allowNull: false }, message_type: { type: DataTypes.ENUM('text', 'plan', 'execution', 'feedback'), defaultValue: 'text', allowNull: false }, metadata: { type: DataTypes.JSONB, defaultValue: {}, allowNull: false }, tokens_used: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }, processing_time: { type: DataTypes.FLOAT, defaultValue: 0, allowNull: false }, created_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW }, updated_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW } }); // Create indexes await queryInterface.addIndex('messages', ['conversation_id']); await queryInterface.addIndex('messages', ['plan_id']); await queryInterface.addIndex('messages', ['role']); await queryInterface.addIndex('messages', ['message_type']); await queryInterface.addIndex('messages', ['created_at']); }, down: async (queryInterface, Sequelize) => { await queryInterface.dropTable('messages'); } };