Skip to content

Build your personal knowledge base with Trilium Notes

feat(server): add option to mount database read-only

FliegendeWurstfd0f0196cc54
diff --git a/apps/server/src/services/config.ts b/apps/server/src/services/config.ts
index 1d7cc9dec3..2089c03ced 100644
--- a/apps/server/src/services/config.ts
+++ b/apps/server/src/services/config.ts
@@ -21,6 +21,7 @@ export interface TriliumConfig {
noAuthentication: boolean;
noBackup: boolean;
noDesktopIcon: boolean;
+ readOnly: boolean;
};
Network: {
host: string;
@@ -62,7 +63,10 @@ const config: TriliumConfig = {
envToBoolean(process.env.TRILIUM_GENERAL_NOBACKUP) || iniConfig.General.noBackup || false,
noDesktopIcon:
- envToBoolean(process.env.TRILIUM_GENERAL_NODESKTOPICON) || iniConfig.General.noDesktopIcon || false
+ envToBoolean(process.env.TRILIUM_GENERAL_NODESKTOPICON) || iniConfig.General.noDesktopIcon || false,
+
+ readOnly:
+ envToBoolean(process.env.TRILIUM_GENERAL_READONLY) || iniConfig.General.readOnly || false
},
Network: {
diff --git a/apps/server/src/services/sql.ts b/apps/server/src/services/sql.ts
index f686b0876d..84ddf107b1 100644
--- a/apps/server/src/services/sql.ts
+++ b/apps/server/src/services/sql.ts
@@ -13,18 +13,20 @@ import Database from "better-sqlite3";
import ws from "./ws.js";
import becca_loader from "../becca/becca_loader.js";
import entity_changes from "./entity_changes.js";
+import config from "./config.js";
let dbConnection: DatabaseType = buildDatabase();
let statementCache: Record<string, Statement> = {};
function buildDatabase() {
+ // for integration tests, ignore the config's readOnly setting
if (process.env.TRILIUM_INTEGRATION_TEST === "memory") {
return buildIntegrationTestDatabase();
} else if (process.env.TRILIUM_INTEGRATION_TEST === "memory-no-store") {
return new Database(":memory:");
}
- return new Database(dataDir.DOCUMENT_PATH);
+ return new Database(dataDir.DOCUMENT_PATH, { readonly: config.General.readOnly });
}
function buildIntegrationTestDatabase(dbPath?: string) {