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

82 lines
1.8 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
/**
* Story Model
* Table: stories
* Stores story data with metadata, vocabulary, context, grades, and tags
*/
const Story = sequelize.define('stories', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
allowNull: false,
comment: 'Unique identifier for the story (UUID)'
},
name: {
type: DataTypes.STRING(255),
allowNull: false,
comment: 'Story title/name'
},
logo: {
type: DataTypes.TEXT,
allowNull: true,
comment: 'URL to story logo/thumbnail image'
},
vocabulary: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: 'Array of vocabulary words used in the story'
},
context: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: 'Array of story context objects with images, text, audio data'
},
grade: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: 'Array of grade levels (e.g., ["Grade 1", "Grade 2"])'
},
tag: {
type: DataTypes.JSON,
allowNull: true,
defaultValue: [],
comment: 'Array of tags for categorization (e.g., ["adventure", "friendship"])'
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: 'Record creation timestamp'
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: 'Record last update timestamp'
}
}, {
tableName: 'stories',
timestamps: true,
underscored: true,
indexes: [
{
name: 'idx_name',
fields: ['name']
},
{
name: 'idx_created_at',
fields: ['created_at']
}
],
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
});
module.exports = Story;