const { DataTypes } = require('sequelize'); module.exports = { up: async (queryInterface, Sequelize) => { await queryInterface.createTable('plans', { 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' }, title: { type: DataTypes.STRING, allowNull: false }, description: { type: DataTypes.TEXT, allowNull: false }, steps: { type: DataTypes.JSONB, allowNull: false }, status: { type: DataTypes.ENUM('draft', 'pending_approval', 'approved', 'rejected', 'executing', 'completed', 'failed'), defaultValue: 'draft', allowNull: false }, approval_feedback: { type: DataTypes.TEXT, allowNull: true }, execution_result: { type: DataTypes.JSONB, defaultValue: {}, allowNull: false }, tools_required: { type: DataTypes.ARRAY(DataTypes.STRING), defaultValue: [], allowNull: false }, estimated_duration: { type: DataTypes.INTEGER, allowNull: true }, complexity_score: { type: DataTypes.FLOAT, defaultValue: 0, allowNull: false }, metadata: { type: DataTypes.JSONB, defaultValue: {}, 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('plans', ['conversation_id']); await queryInterface.addIndex('plans', ['status']); await queryInterface.addIndex('plans', ['created_at']); }, down: async (queryInterface, Sequelize) => { await queryInterface.dropTable('plans'); } };