diegosouzapw/OmniRoute · error

[Migration] Failed to create pre-migration backup

Error message

[Migration] Failed to create pre-migration backup: ${message}

What it means

Creating the pre-migration safety backup via 'VACUUM INTO' failed before running pending migrations. Common causes: insufficient disk space (backup doubles DB size), unwritable backup directory, or database lock. The migration runner proceeds cautiously — without the backup, a failed migration cannot be rolled back from this snapshot.

Solutions

  1. Free disk space before restarting with pending migrations
  2. Check write permissions on the migration backup directory
  3. Manually back up the SQLite file, then let migrations run
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/lib/db/migrationRunner.ts:917 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/c823c334e338ce85. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/migrationRunner.ts:917

      fs.mkdirSync(backupDir, { recursive: true });
    }

    const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
    const backupPath = path.join(backupDir, `db_${timestamp}_pre-migration.sqlite`);
    const escapedBackupPath = backupPath.replace(/'/g, "''");

    db.exec(`VACUUM INTO '${escapedBackupPath}'`);
    console.log(`[Migration] Pre-migration backup created: ${backupPath}`);

    // #10421: apply the operator's retention budget right here. Without this the
    // migration path was the one backup producer that never pruned, so every process
    // start with a pending migration added ~5 MB forever (observed: 49k files / 204 GB).
    pruneMigrationBackups(db, backupDir);

    return backupPath;
  } catch (err: unknown) {
    const message = err instanceof Error ? err.message : String(err);
    console.warn(`[Migration] Failed to create pre-migration backup: ${message}`);
    return null;
  }
}

/**
 * Run all pending migrations in order.
 * Returns the number of migrations applied.
 *
 * Includes safety checks:
 * 1. Detects migration name mismatches (renumbering) and warns
 * 2. Aborts if too many pending migrations on an existing DB (likely wipe)
 * 3. Creates automatic backup before running any migrations
 */
export function runMigrations(db: SqliteAdapter, options?: { isNewDb?: boolean }): number {
  const isNewDb = options?.isNewDb === true;
  ensureMigrationsTable(db);

  const files = filterSupersededDuplicateMigrations(getMigrationFiles());

View on GitHub (pinned to a179ffed5b)