fix(server): prevent NaN potentially corrupting the backup when migrating

This commit is contained in:
Elian Doran
2026-04-17 23:03:28 +03:00
parent 06f7818ee3
commit 64bc1271e1
2 changed files with 7 additions and 1 deletions

View File

@@ -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"

View File

@@ -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 }));
}