{"record":{"id":"c823c334e338ce85","repo":"diegosouzapw/OmniRoute","slug":"migration-failed-to-create-pre-migration-backup","errorCode":null,"errorMessage":"[Migration] Failed to create pre-migration backup: ${message}","messagePattern":"\\[Migration\\] Failed to create pre-migration backup: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/db/migrationRunner.ts","lineNumber":917,"sourceCode":"      fs.mkdirSync(backupDir, { recursive: true });\n    }\n\n    const timestamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n    const backupPath = path.join(backupDir, `db_${timestamp}_pre-migration.sqlite`);\n    const escapedBackupPath = backupPath.replace(/'/g, \"''\");\n\n    db.exec(`VACUUM INTO '${escapedBackupPath}'`);\n    console.log(`[Migration] Pre-migration backup created: ${backupPath}`);\n\n    // #10421: apply the operator's retention budget right here. Without this the\n    // migration path was the one backup producer that never pruned, so every process\n    // start with a pending migration added ~5 MB forever (observed: 49k files / 204 GB).\n    pruneMigrationBackups(db, backupDir);\n\n    return backupPath;\n  } catch (err: unknown) {\n    const message = err instanceof Error ? err.message : String(err);\n    console.warn(`[Migration] Failed to create pre-migration backup: ${message}`);\n    return null;\n  }\n}\n\n/**\n * Run all pending migrations in order.\n * Returns the number of migrations applied.\n *\n * Includes safety checks:\n * 1. Detects migration name mismatches (renumbering) and warns\n * 2. Aborts if too many pending migrations on an existing DB (likely wipe)\n * 3. Creates automatic backup before running any migrations\n */\nexport function runMigrations(db: SqliteAdapter, options?: { isNewDb?: boolean }): number {\n  const isNewDb = options?.isNewDb === true;\n  ensureMigrationsTable(db);\n\n  const files = filterSupersededDuplicateMigrations(getMigrationFiles());","sourceCodeStart":899,"sourceCodeEnd":935,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/migrationRunner.ts#L899-L935","documentation":"Error \"[Migration] Failed to create pre-migration backup: ${message}\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/db/migrationRunner.ts:917 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}