Files
starr-philproperties/models/courses/unit_lessons.mdl.js
T
kennethobsequio bb7e8fde08 add: ver()
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-07-08 11:31:40 +08:00

33 lines
1.7 KiB
JavaScript

/***********************************************************************************************************************************************************************
* File Name: unit_lessons.mdl.js
* Type of Program: Model (junction)
* Description: Attaches a standalone Lesson to a Unit. A Lesson can live in many
* Units; per-unit ordering lives here (order_index), not on the
* Lesson itself. Detaching removes the row — the Lesson survives.
*
* Author: Kenneth Obsequio (@lash0000)
* Date Created: Jul. 7, 2026
***********************************************************************************************************************************************************************/
const { DataTypes } = require("sequelize");
const sequelize = require("../../config/db.config");
const UnitLesson = sequelize.define("UnitLesson", {
unit_lesson_id: { type: DataTypes.BIGINT, primaryKey: true, autoIncrement: true },
unit_id: { type: DataTypes.BIGINT, allowNull: false },
lesson_id: { type: DataTypes.BIGINT, allowNull: false },
order_index: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
createdBy: { type: DataTypes.BIGINT, allowNull: true },
updatedBy: { type: DataTypes.BIGINT, allowNull: true },
}, {
tableName: "unit_lessons",
timestamps: true,
indexes: [
{ unique: true, fields: ["unit_id", "lesson_id"], name: "uq_unit_lessons_unit_lesson" },
{ fields: ["unit_id"], name: "idx_unit_lessons_unit_id" },
{ fields: ["lesson_id"], name: "idx_unit_lessons_lesson_id" },
{ fields: ["order_index"], name: "idx_unit_lessons_order" },
],
});
module.exports = UnitLesson;