const { DataTypes } = require('sequelize'); const { sequelize } = require('../config/database'); const VocabRelation = sequelize.define('VocabRelation', { relation_id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, comment: 'Unique identifier for vocabulary relation' }, vocab_id: { type: DataTypes.UUID, allowNull: false, references: { model: 'vocab', key: 'vocab_id' }, onDelete: 'CASCADE', comment: 'Reference to vocabulary entry' }, relation_type: { type: DataTypes.ENUM('synonym', 'antonym', 'related'), allowNull: false, comment: 'Type of relation (synonym, antonym, related)' }, related_word: { type: DataTypes.STRING(100), allowNull: false, comment: 'The related word (e.g., consume, dine, fast)' }, related_vocab_id: { type: DataTypes.UUID, references: { model: 'vocab', key: 'vocab_id' }, onDelete: 'SET NULL', comment: 'Reference to related vocab entry if it exists in system' }, created_at: { type: DataTypes.DATE, defaultValue: DataTypes.NOW } }, { tableName: 'vocab_relation', timestamps: true, createdAt: 'created_at', updatedAt: false, indexes: [ { name: 'idx_vocab_relation_vocab', fields: ['vocab_id'] }, { name: 'idx_vocab_relation_type', fields: ['relation_type'] }, { name: 'idx_vocab_relation_related', fields: ['related_vocab_id'] } ] }); module.exports = VocabRelation;