{"record":{"id":"ac95970ff9dff364","repo":"diegosouzapw/OmniRoute","slug":"db-failed-to-verify-usage-history-account-index","errorCode":null,"errorMessage":"[DB] Failed to verify usage_history account index:","messagePattern":"\\[DB\\] Failed to verify usage_history account index:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/db/schemaColumns.ts","lineNumber":97,"sourceCode":"    );\n    db.exec(\n      \"CREATE INDEX IF NOT EXISTS idx_pc_auth_active_refresh ON provider_connections(auth_type, is_active, refresh_token)\"\n    );\n    db.exec(\n      \"CREATE INDEX IF NOT EXISTS idx_pc_provider_auth_type ON provider_connections(provider, auth_type)\"\n    );\n  } catch (error: unknown) {\n    const message = error instanceof Error ? error.message : String(error);\n    console.warn(\"[DB] Failed to verify provider_connections schema:\", message);\n  }\n}\n\nexport function ensureUsageHistoryAccountIndex(db: SqliteDatabase) {\n  try {\n    db.exec(\"CREATE INDEX IF NOT EXISTS idx_uh_account_key ON usage_history(account_key)\");\n  } catch (error: unknown) {\n    const message = error instanceof Error ? error.message : String(error);\n    console.warn(\"[DB] Failed to verify usage_history account index:\", message);\n  }\n}\n\nexport function ensureUsageHistoryColumns(db: SqliteDatabase) {\n  try {\n    const columns = db.prepare(\"PRAGMA table_info(usage_history)\").all() as Array<{\n      name?: string;\n    }>;\n    const columnNames = new Set(columns.map((column) => String(column.name ?? \"\")));\n\n    if (!columnNames.has(\"success\")) {\n      db.exec(\"ALTER TABLE usage_history ADD COLUMN success INTEGER DEFAULT 1\");\n      console.log(\"[DB] Added usage_history.success column\");\n    }\n    if (!columnNames.has(\"latency_ms\")) {\n      db.exec(\"ALTER TABLE usage_history ADD COLUMN latency_ms INTEGER DEFAULT 0\");\n      console.log(\"[DB] Added usage_history.latency_ms column\");\n    }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/db/schemaColumns.ts#L79-L115","documentation":"Creating the idx_uh_account index on usage_history failed during the defensive schema-verification pass — e.g. the database is locked, the table is missing, or the SQL was rejected. Query performance for account-scoped usage lookups may degrade (full table scans) until the index exists.","triggerScenarios":"Thrown at src/lib/db/schemaColumns.ts:97 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run CREATE INDEX IF NOT EXISTS idx_uh_account manually","Check for concurrent write locks during startup","Verify the usage_history table exists"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}