85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../config/database');
|
|
|
|
const Grammar = sequelize.define('Grammar', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true
|
|
},
|
|
grammar_code: {
|
|
type: DataTypes.STRING(100),
|
|
allowNull: false,
|
|
unique: true,
|
|
comment: 'Unique identifier for grammar rule (e.g., "gram-001-present-cont")'
|
|
},
|
|
title: {
|
|
type: DataTypes.STRING(200),
|
|
allowNull: false,
|
|
comment: 'Grammar rule name (e.g., "Present Continuous")'
|
|
},
|
|
translation: {
|
|
type: DataTypes.STRING(200),
|
|
allowNull: true,
|
|
comment: 'Vietnamese translation'
|
|
},
|
|
|
|
// GENERATIVE LOGIC
|
|
structure: {
|
|
type: DataTypes.JSON,
|
|
allowNull: false,
|
|
defaultValue: {},
|
|
comment: 'Formula and pattern_logic for sentence generation. Structure: { formula: string, pattern_logic: array }'
|
|
},
|
|
|
|
// METADATA
|
|
instructions: {
|
|
type: DataTypes.JSON,
|
|
allowNull: true,
|
|
defaultValue: {},
|
|
comment: 'Instructions and hints. Structure: { vi: string, hint: string }'
|
|
},
|
|
|
|
// ATTRIBUTES
|
|
difficulty_score: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
defaultValue: 1,
|
|
validate: {
|
|
min: 1,
|
|
max: 10
|
|
},
|
|
comment: 'Difficulty level from 1 (easiest) to 10 (hardest)'
|
|
},
|
|
category: {
|
|
type: DataTypes.STRING(100),
|
|
allowNull: true,
|
|
comment: 'Grammar category (e.g., "Tenses", "Modal Verbs", "Questions")'
|
|
},
|
|
tags: {
|
|
type: DataTypes.JSON,
|
|
allowNull: true,
|
|
defaultValue: [],
|
|
comment: 'Array of tags for categorization'
|
|
},
|
|
|
|
// STATUS
|
|
is_active: {
|
|
type: DataTypes.BOOLEAN,
|
|
allowNull: false,
|
|
defaultValue: true,
|
|
comment: 'Soft delete flag'
|
|
}
|
|
}, {
|
|
tableName: 'grammars',
|
|
timestamps: true,
|
|
indexes: [
|
|
{ fields: ['grammar_code'], unique: true },
|
|
{ fields: ['category'] },
|
|
{ fields: ['difficulty_score'] },
|
|
{ fields: ['is_active'] }
|
|
]
|
|
});
|
|
|
|
module.exports = Grammar;
|