units,lesson as standalone

This commit is contained in:
2026-07-10 11:44:46 +08:00
parent 86fba50b95
commit e1ffdab190
46 changed files with 1463 additions and 197 deletions
@@ -0,0 +1,39 @@
'use strict';
// Part 1B — task_lists' tasks currently sort only by createdAt (no ordering
// column exists). Add order_index (position within the list) and is_required
// (mirrors unit_quizzes.is_required — an optional task doesn't block anything
// after it in the sequencing lock).
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('tasks', 'order_index', {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
after: 'deadline',
});
await queryInterface.addColumn('tasks', 'is_required', {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: true,
after: 'order_index',
});
// Backfill existing rows with a stable order matching current createdAt
// sort, so tasks don't all collapse to order_index 0 on first use.
await queryInterface.sequelize.query(`
UPDATE tasks t SET order_index = sub.rn - 1
FROM (
SELECT task_id, ROW_NUMBER() OVER (PARTITION BY task_list_id ORDER BY "createdAt" ASC) AS rn
FROM tasks
) sub
WHERE t.task_id = sub.task_id
`);
},
async down(queryInterface) {
await queryInterface.removeColumn('tasks', 'is_required');
await queryInterface.removeColumn('tasks', 'order_index');
},
};