Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(server): prevent NaN potentially corrupting the backup when migrating
Elian Doran64bc1271e178
diff --git a/apps/server/src/assets/translations/en/server.json b/apps/server/src/assets/translations/en/server.jsonindex 8542592a8f..23c8347aee 100644--- a/apps/server/src/assets/translations/en/server.json+++ b/apps/server/src/assets/translations/en/server.json@@ -397,7 +397,8 @@"migration": {"old_version": "Direct migration from your current version is not supported. Please upgrade to the latest v0.60.4 first and only then to this version.","error_message": "Error during migration to version {{version}}: {{stack}}",- "wrong_db_version": "The version of the database ({{version}}) is newer than what the application expects ({{targetVersion}}), which means that it was created by a newer and incompatible version of Trilium. Upgrade to the latest version of Trilium to resolve this issue."+ "wrong_db_version": "The version of the database ({{version}}) is newer than what the application expects ({{targetVersion}}), which means that it was created by a newer and incompatible version of Trilium. Upgrade to the latest version of Trilium to resolve this issue.",+ "invalid_db_version": "The database version is not a valid number. This usually indicates a corrupted 'dbVersion' option in the database. Please restore from a backup."},"modals": {"error_title": "Error"diff --git a/apps/server/src/services/migration.ts b/apps/server/src/services/migration.tsindex df43e42bd2..4edb9fb028 100644--- a/apps/server/src/services/migration.ts+++ b/apps/server/src/services/migration.ts@@ -130,6 +130,11 @@ function isDbUpToDate() {async function migrateIfNecessary() {const currentDbVersion = getDbVersion();+ if (isNaN(currentDbVersion)) {+ await crash(t("migration.invalid_db_version"));+ return;+ }+if (currentDbVersion > appInfo.dbVersion && process.env.TRILIUM_IGNORE_DB_VERSION !== "true") {await crash(t("migration.wrong_db_version", { version: currentDbVersion, targetVersion: appInfo.dbVersion }));}