Files
sena_db_api_layer/models/GrammarMapping.js
silverpro89 2c7b4675a7 update
2026-01-26 20:23:08 +07:00

57 lines
1.3 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const GrammarMapping = sequelize.define('GrammarMapping', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
grammar_id: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'grammars',
key: 'id'
},
onDelete: 'CASCADE',
comment: 'Foreign key to grammars table'
},
book_id: {
type: DataTypes.STRING(100),
allowNull: false,
comment: 'Book identifier (e.g., "global-success-2")'
},
grade: {
type: DataTypes.INTEGER,
allowNull: false,
comment: 'Grade level'
},
unit: {
type: DataTypes.INTEGER,
allowNull: true,
comment: 'Unit number in the book'
},
lesson: {
type: DataTypes.INTEGER,
allowNull: true,
comment: 'Lesson number within the unit'
},
context_note: {
type: DataTypes.TEXT,
allowNull: true,
comment: 'Additional context about where this grammar appears'
}
}, {
tableName: 'grammar_mappings',
timestamps: true,
indexes: [
{ fields: ['grammar_id'] },
{ fields: ['book_id'] },
{ fields: ['grade'] },
{ fields: ['book_id', 'grade', 'unit', 'lesson'] }
]
});
module.exports = GrammarMapping;