pushy

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-06-28 11:29:07 +08:00
parent 463a8d3978
commit 89acdfc239
67 changed files with 2736 additions and 306 deletions
+42
View File
@@ -0,0 +1,42 @@
/**
* One-time backfill: recompute duration_seconds for every lesson
* that has at least one saved page block.
*
* Run from the project root:
* node scripts/backfill-durations.js
*/
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '../.env') });
const sequelize = require('../config/db.config');
const LessonPage = require('../models/courses/lesson_page.mdl');
const { recomputeDurations } = require('../utils/duration.util');
(async () => {
await sequelize.authenticate();
console.log('DB connected.\n');
const pages = await LessonPage.findAll({
attributes: ['lesson_id', 'blocks'],
where: sequelize.literal(`jsonb_array_length(blocks::jsonb) > 0`),
});
console.log(`Found ${pages.length} lessons with blocks. Recomputing...`);
let ok = 0, fail = 0;
for (const page of pages) {
try {
await recomputeDurations(page.lesson_id);
process.stdout.write('.');
ok++;
} catch (err) {
process.stdout.write('✗');
console.error(`\n lesson ${page.lesson_id}: ${err.message}`);
fail++;
}
}
console.log(`\n\nDone — ${ok} recomputed, ${fail} failed.`);
await sequelize.close();
})();