fix(db): prevent native module errors from renaming db and bump mass-migration safety threshold

This commit is contained in:
diegosouzapw
2026-04-16 15:58:24 -03:00
parent f5700f2b4c
commit 661a63cc45
3 changed files with 14 additions and 3 deletions

4
package-lock.json generated
View File

@@ -51,7 +51,7 @@
"zustand": "^5.0.10"
},
"bin": {
"omniroute": "bin/omniroute.ts",
"omniroute": "bin/omniroute.mjs",
"omniroute-reset-password": "bin/reset-password.mjs"
},
"devDependencies": {
@@ -84,7 +84,7 @@
"wtfnode": "^0.10.1"
},
"engines": {
"node": ">=20.20.2 <21 || >=22.22.2 <23"
"node": ">=20.20.2 <21 || >=22.22.2 <23 || >=24.0.0 <25"
},
"optionalDependencies": {
"keytar": "^7.9.0"

View File

@@ -882,6 +882,17 @@ export function getDbInstance(): SqliteDatabase {
} catch (e: unknown) {
const message = e instanceof Error ? e.message : String(e);
console.warn("[DB] Could not probe existing DB:", message);
// If the error is a Node module/ABI failure, throw it immediately to avoid renaming the database
if (
message.includes("Module did not self-register") ||
message.includes("could not be found") ||
message.includes("ERR_DLOPEN_FAILED") ||
(e as any)?.code === "ERR_DLOPEN_FAILED"
) {
throw e;
}
// SAFETY: Never delete the database — rename to backup so data can be recovered.
// The old code would silently destroy all user data on any probe failure.
const failedPath = sqliteFile + `.probe-failed-${Date.now()}`;

View File

@@ -48,7 +48,7 @@ const MIGRATIONS_DIR = resolveMigrationsDir();
*
* Set to 0 to disable this safety check.
*/
const MAX_PENDING_MIGRATIONS_ON_EXISTING_DB = 5;
const MAX_PENDING_MIGRATIONS_ON_EXISTING_DB = 50;
const RENAMED_MIGRATION_COMPATIBILITY = [
{