diegosouzapw/OmniRoute · error

[DB] Failed to verify api_keys schema:

Error message

[DB] Failed to verify api_keys schema:

What it means

The startup schema self-heal for the api_keys table (PRAGMA table_info plus ALTER TABLE ADD COLUMN fallbacks) threw an unexpected error, so it is unknown whether all required columns exist. The _schemaChecked flag remains false so the check will be retried on the next call rather than being wrongly marked complete.

Solutions

  1. Inspect the logged error for the failing statement (often a locked or corrupted database)
  2. Run PRAGMA table_info(api_keys) manually to see current columns
  3. Restore from a DB backup if the schema is corrupted
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/lib/db/apiKeys.ts:415 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/00b863c850043f1f. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/db/apiKeys.ts:415

): void {
  if (columnNames.has(column.name)) return;
  db.exec(`ALTER TABLE api_keys ADD COLUMN ${column.definition}`);
  console.log(`[DB] Added api_keys.${column.name} column`);
}

function ensureApiKeysColumns(db: ApiKeysDbLike) {
  if (_schemaChecked) return;

  try {
    const columns = db.prepare<ApiKeyRow>("PRAGMA table_info(api_keys)").all();
    const columnNames = new Set(columns.map((column) => String(column.name ?? "")));
    for (const column of API_KEY_COLUMN_FALLBACKS) {
      ensureApiKeyColumn(db, columnNames, column);
    }
    _schemaChecked = true;
  } catch (error) {
    const message = error instanceof Error ? error.message : String(error);
    console.warn("[DB] Failed to verify api_keys schema:", message);
  }
}

let _stmtDb: ApiKeysDbLike | null = null;
function getPreparedStatements(db: ApiKeysDbLike): ApiKeysStatements {
  ensureApiKeysColumns(db);

  if (
    !_stmtGetAllKeys ||
    !_stmtGetKeyById ||
    !_stmtValidateKey ||
    !_stmtGetKeyMetadata ||
    !_stmtInsertKey ||
    !_stmtDeleteKey ||
    _stmtDb !== db
  ) {
    _stmtDb = db;
    _stmtGetAllKeys = db.prepare<ApiKeyRow>("SELECT * FROM api_keys ORDER BY created_at");

View on GitHub (pinned to a179ffed5b)