Files
reason-flow/server/migrations/009_create_tool_executions.js
T
2025-11-06 11:08:59 +01:00

96 lines
2.5 KiB
JavaScript

const { DataTypes } = require('sequelize');
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('tool_executions', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false
},
plan_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'plans',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
},
document_id: {
type: DataTypes.UUID,
allowNull: true,
references: {
model: 'documents',
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'SET NULL'
},
tool_name: {
type: DataTypes.STRING,
allowNull: false
},
tool_type: {
type: DataTypes.ENUM('query_expander', 'extraction', 'report1', 'report2', 'web_search', 'encyclopedia_pdf'),
allowNull: false
},
input_parameters: {
type: DataTypes.JSONB,
allowNull: false
},
output_result: {
type: DataTypes.JSONB,
allowNull: true
},
status: {
type: DataTypes.ENUM('pending', 'running', 'completed', 'failed'),
defaultValue: 'pending',
allowNull: false
},
execution_time: {
type: DataTypes.FLOAT,
allowNull: true
},
error_message: {
type: DataTypes.TEXT,
allowNull: true
},
tokens_used: {
type: DataTypes.INTEGER,
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('tool_executions', ['plan_id']);
await queryInterface.addIndex('tool_executions', ['document_id']);
await queryInterface.addIndex('tool_executions', ['tool_name']);
await queryInterface.addIndex('tool_executions', ['tool_type']);
await queryInterface.addIndex('tool_executions', ['status']);
await queryInterface.addIndex('tool_executions', ['created_at']);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('tool_executions');
}
};