From ff08eadb23fcfe59197da4d4a0361a06d92c78b5 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 6 Dec 2025 10:49:14 +0200 Subject: [PATCH] fix(server/scripts): generate-document failing (closes #5422) --- apps/server/scripts/generate_document.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/server/scripts/generate_document.ts b/apps/server/scripts/generate_document.ts index 8e4dd7227..0b041ad26 100644 --- a/apps/server/scripts/generate_document.ts +++ b/apps/server/scripts/generate_document.ts @@ -6,10 +6,11 @@ import sqlInit from "../src/services/sql_init.js"; import noteService from "../src/services/notes.js"; import attributeService from "../src/services/attributes.js"; -import cls from "../src/services/cls.js"; import cloningService from "../src/services/cloning.js"; -import loremIpsum from "lorem-ipsum"; +import * as loremIpsum from "lorem-ipsum"; import "../src/becca/entity_constructor.js"; +import { initializeTranslations } from "../src/services/i18n.js"; +import cls from "../src/services/cls.js"; const noteCount = parseInt(process.argv[2]); @@ -27,6 +28,16 @@ function getRandomNoteId() { } async function start() { + if (!sqlInit.isDbInitialized()) { + console.error("Database not initialized."); + process.exit(1); + } + + await initializeTranslations(); + + sqlInit.initializeDb(); + await sqlInit.dbReady; + for (let i = 0; i < noteCount; i++) { const title = loremIpsum.loremIpsum({ count: 1, @@ -90,6 +101,4 @@ async function start() { process.exit(0); } -// @TriliumNextTODO sqlInit.dbReady never seems to resolve so program hangs -// see https://github.com/TriliumNext/Trilium/issues/1020 -sqlInit.dbReady.then(cls.wrap(start)).catch((err) => console.error(err)); +cls.init(() => start());