mirror of
https://github.com/zadam/trilium.git
synced 2026-06-18 16:19:46 +02:00
fix(server): not starting due to schema loading
This commit is contained in:
@@ -142,6 +142,7 @@ async function initialize(): Promise<void> {
|
||||
console.log("[Worker] Database loaded");
|
||||
|
||||
console.log("[Worker] Loading @triliumnext/core...");
|
||||
const schemaModule = await import("@triliumnext/core/src/assets/schema.sql?raw");
|
||||
coreModule = await import("@triliumnext/core");
|
||||
await coreModule.initializeCore({
|
||||
executionContext: new BrowserExecutionContext(),
|
||||
@@ -149,6 +150,7 @@ async function initialize(): Promise<void> {
|
||||
messaging: messagingProvider!,
|
||||
request: new FetchRequestProvider(),
|
||||
translations: translationProvider,
|
||||
schema: schemaModule.default,
|
||||
dbConfig: {
|
||||
provider: sqlProvider!,
|
||||
isReadOnly: false,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* are loaded later and will result in an empty string.
|
||||
*/
|
||||
|
||||
import fs from "fs";
|
||||
import { initializeCore } from "@triliumnext/core";
|
||||
import path from "path";
|
||||
|
||||
@@ -50,6 +51,7 @@ async function startApplication() {
|
||||
request: new NodeRequestProvider(),
|
||||
executionContext: new ClsHookedExecutionContext(),
|
||||
messaging: new WebSocketMessagingProvider(),
|
||||
schema: fs.readFileSync(require.resolve("@triliumnext/core/src/assets/schema.sql"), "utf-8"),
|
||||
translations: (await import("./services/i18n.js")).initializeTranslations,
|
||||
extraAppInfo: {
|
||||
nodeVersion: process.version,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
import sqlInit from "../services/sql_init.js";
|
||||
import setupService from "../services/setup.js";
|
||||
import { isElectron } from "../services/utils.js";
|
||||
import assetPath from "../services/asset_path.js";
|
||||
import appPath from "../services/app_path.js";
|
||||
import { i18n, setup as setupService } from "@triliumnext/core";
|
||||
import type { Request, Response } from "express";
|
||||
import { getCurrentLocale } from "../services/i18n.js";
|
||||
|
||||
import appPath from "../services/app_path.js";
|
||||
import assetPath from "../services/asset_path.js";
|
||||
import sqlInit from "../services/sql_init.js";
|
||||
import { isElectron } from "../services/utils.js";
|
||||
|
||||
function setupPage(req: Request, res: Response) {
|
||||
if (sqlInit.isDbInitialized()) {
|
||||
@@ -29,10 +27,10 @@ function setupPage(req: Request, res: Response) {
|
||||
}
|
||||
|
||||
res.render("setup", {
|
||||
syncInProgress: syncInProgress,
|
||||
assetPath: assetPath,
|
||||
appPath: appPath,
|
||||
currentLocale: getCurrentLocale()
|
||||
syncInProgress,
|
||||
assetPath,
|
||||
appPath,
|
||||
currentLocale: i18n.getCurrentLocale()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,24 +2,16 @@ import { type OptionRow } from "@triliumnext/commons";
|
||||
import { sql_init as coreSqlInit } from "@triliumnext/core";
|
||||
import fs from "fs";
|
||||
|
||||
import BBranch from "../becca/entities/bbranch.js";
|
||||
import BNote from "../becca/entities/bnote.js";
|
||||
import BOption from "../becca/entities/boption.js";
|
||||
import cls from "./cls.js";
|
||||
import password from "./encryption/password.js";
|
||||
import hidden_subtree from "./hidden_subtree.js";
|
||||
import zipImportService from "./import/zip.js";
|
||||
import log from "./log.js";
|
||||
import optionService from "./options.js";
|
||||
import resourceDir from "./resource_dir.js";
|
||||
import sql from "./sql.js";
|
||||
import TaskContext from "./task_context.js";
|
||||
|
||||
const schemaExists = coreSqlInit.schemaExists;
|
||||
const isDbInitialized = coreSqlInit.isDbInitialized;
|
||||
const dbReady = coreSqlInit.dbReady;
|
||||
const setDbAsInitialized = coreSqlInit.setDbAsInitialized;
|
||||
const initDbConnection = coreSqlInit.initDbConnection;
|
||||
const createInitialDatabase = coreSqlInit.createInitialDatabase;
|
||||
const initializeDb = coreSqlInit.initializeDb;
|
||||
export const getDbSize = coreSqlInit.getDbSize;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { SqlService, SqlServiceParams } from "./services/sql/sql";
|
||||
import { initMessaging, MessagingProvider } from "./services/messaging/index";
|
||||
import { initRequest, RequestProvider } from "./services/request";
|
||||
import { initTranslations, TranslationProvider } from "./services/i18n";
|
||||
import { initSchema } from "./services/sql_init";
|
||||
import appInfo from "./services/app_info";
|
||||
|
||||
export type * from "./services/sql/types";
|
||||
@@ -87,13 +88,15 @@ export { default as sync } from "./services/sync";
|
||||
export { default as consistency_checks } from "./services/consistency_checks";
|
||||
export { default as content_hash } from "./services/content_hash";
|
||||
export { default as sync_mutex } from "./services/sync_mutex";
|
||||
export { default as setup } from "./services/setup";
|
||||
export type { RequestProvider, ExecOpts, CookieJar } from "./services/request";
|
||||
|
||||
export async function initializeCore({ dbConfig, executionContext, crypto, translations, messaging, request, extraAppInfo }: {
|
||||
export async function initializeCore({ dbConfig, executionContext, crypto, translations, messaging, request, schema, extraAppInfo }: {
|
||||
dbConfig: SqlServiceParams,
|
||||
executionContext: ExecutionContext,
|
||||
crypto: CryptoProvider,
|
||||
translations: TranslationProvider,
|
||||
schema: string,
|
||||
messaging?: MessagingProvider,
|
||||
request?: RequestProvider,
|
||||
extraAppInfo?: {
|
||||
@@ -106,6 +109,7 @@ export async function initializeCore({ dbConfig, executionContext, crypto, trans
|
||||
initCrypto(crypto);
|
||||
initSql(new SqlService(dbConfig, getLog()));
|
||||
initContext(executionContext);
|
||||
initSchema(schema);
|
||||
Object.assign(appInfo, extraAppInfo);
|
||||
if (messaging) {
|
||||
initMessaging(messaging);
|
||||
|
||||
@@ -9,12 +9,17 @@ import { getContext } from "./context";
|
||||
import config from "./config";
|
||||
import BNote from "../becca/entities/bnote";
|
||||
import BBranch from "../becca/entities/bbranch";
|
||||
import schema from "../assets/schema.sql?raw";
|
||||
import hidden_subtree from "./hidden_subtree";
|
||||
import TaskContext from "./task_context";
|
||||
|
||||
export const dbReady = deferred<void>();
|
||||
|
||||
let schema: string;
|
||||
|
||||
export function initSchema(schemaStr: string) {
|
||||
schema = schemaStr;
|
||||
}
|
||||
|
||||
function schemaExists() {
|
||||
return !!getSql().getValue(/*sql*/`SELECT name FROM sqlite_master
|
||||
WHERE type = 'table' AND name = 'options'`);
|
||||
|
||||
Reference in New Issue
Block a user