diegosouzapw/OmniRoute · error
[DB] Failed to verify usage_history schema:
Error message
[DB] Failed to verify usage_history schema:
What it means
The defensive verification/healing of the usage_history schema (adding columns like account_label_priority, creating the provider/model/timestamp and dedup indexes) threw an unexpected error. The table may be missing some columns or indexes, which can break usage queries or dedup logic until the schema is repaired.
Solutions
- Inspect the logged error for the failing ALTER/CREATE INDEX
- Compare PRAGMA table_info(usage_history) with the expected columns
- Apply missing DDL manually or restore from backup
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/lib/db/schemaColumns.ts:162 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/88b3cb6f2d101229.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/db/schemaColumns.ts:162
console.log("[DB] Added usage_history.account_label_priority column");
}
db.exec(
"CREATE INDEX IF NOT EXISTS idx_uh_provider_model_timestamp ON usage_history(provider, model, timestamp)"
);
db.exec(
`CREATE INDEX IF NOT EXISTS idx_uh_dedup ON usage_history(
timestamp,
COALESCE(provider, ''),
COALESCE(model, ''),
COALESCE(connection_id, ''),
COALESCE(api_key_id, ''),
tokens_input,
tokens_output
)`
);
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
console.warn("[DB] Failed to verify usage_history schema:", message);
}
}
export function ensureCallLogsColumns(db: SqliteDatabase) {
try {
const columns = db.prepare("PRAGMA table_info(call_logs)").all() as Array<{
name?: string;
}>;
const columnNames = new Set(columns.map((column) => String(column.name ?? "")));
if (!columnNames.has("artifact_relpath")) {
db.exec("ALTER TABLE call_logs ADD COLUMN artifact_relpath TEXT");
console.log("[DB] Added call_logs.artifact_relpath column");
}
if (!columnNames.has("has_pipeline_details")) {
db.exec("ALTER TABLE call_logs ADD COLUMN has_pipeline_details INTEGER DEFAULT 0");
console.log("[DB] Added call_logs.has_pipeline_details column");
}View on GitHub (pinned to a179ffed5b)