Files
2025-11-06 11:08:59 +01:00

70 lines
2.3 KiB
JavaScript

const { sequelize } = require('../config/database');
const { DataTypes } = require('sequelize');
// Import all models
const User = require('./User')(sequelize, DataTypes);
const Conversation = require('./Conversation')(sequelize, DataTypes);
const Message = require('./Message')(sequelize, DataTypes);
const Plan = require('./Plan')(sequelize, DataTypes);
const Feedback = require('./Feedback')(sequelize, DataTypes);
const Document = require('./Document')(sequelize, DataTypes);
const TrainingData = require('./TrainingData')(sequelize, DataTypes);
const ModelVersion = require('./ModelVersion')(sequelize, DataTypes);
const ToolExecution = require('./ToolExecution')(sequelize, DataTypes);
// Define associations
const defineAssociations = () => {
// User associations
User.hasMany(Conversation, { foreignKey: 'user_id' });
User.hasMany(Feedback, { foreignKey: 'user_id' });
// Conversation associations
Conversation.belongsTo(User, { foreignKey: 'user_id' });
Conversation.hasMany(Message, { foreignKey: 'conversation_id' });
Conversation.hasMany(Plan, { foreignKey: 'conversation_id' });
// Message associations
Message.belongsTo(Conversation, { foreignKey: 'conversation_id' });
Message.belongsTo(Plan, { foreignKey: 'plan_id' });
// Plan associations
Plan.belongsTo(Conversation, { foreignKey: 'conversation_id' });
Plan.hasMany(Message, { foreignKey: 'plan_id' });
Plan.hasMany(ToolExecution, { foreignKey: 'plan_id' });
// Feedback associations
Feedback.belongsTo(User, { foreignKey: 'user_id' });
Feedback.belongsTo(Message, { foreignKey: 'message_id' });
// Document associations
Document.hasMany(ToolExecution, { foreignKey: 'document_id' });
// TrainingData associations
TrainingData.belongsTo(ModelVersion, { foreignKey: 'model_version_id' });
// ModelVersion associations
ModelVersion.hasMany(TrainingData, { foreignKey: 'model_version_id' });
// ToolExecution associations
ToolExecution.belongsTo(Plan, { foreignKey: 'plan_id' });
ToolExecution.belongsTo(Document, { foreignKey: 'document_id' });
};
// Initialize associations
defineAssociations();
const models = {
User,
Conversation,
Message,
Plan,
Feedback,
Document,
TrainingData,
ModelVersion,
ToolExecution,
sequelize
};
module.exports = models;