Files
reason-flow/server/migrations/002_create_conversations.js
2025-11-06 11:08:59 +01:00

63 lines
1.5 KiB
JavaScript

const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('conversations', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
user_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'users',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
title: {
type: DataTypes.STRING,
allowNull: false
},
status: {
type: DataTypes.ENUM('active', 'completed', 'archived'),
defaultValue: 'active',
allowNull: false
},
context: {
type: DataTypes.JSONB,
defaultValue: {},
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('conversations', ['user_id']);
await queryInterface.addIndex('conversations', ['status']);
await queryInterface.addIndex('conversations', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('conversations');
}
};