diff --git a/src/lib/db/core.ts b/src/lib/db/core.ts index a69db56e64..9d8e928864 100644 --- a/src/lib/db/core.ts +++ b/src/lib/db/core.ts @@ -408,7 +408,12 @@ const SCHEMA_SQL = ` CREATE INDEX IF NOT EXISTS idx_cl_timestamp ON call_logs(timestamp); CREATE INDEX IF NOT EXISTS idx_cl_status ON call_logs(status); CREATE INDEX IF NOT EXISTS idx_cl_provider_timestamp ON call_logs(provider, timestamp); - CREATE INDEX IF NOT EXISTS idx_cl_request_provider ON call_logs(request_type, provider); + -- idx_cl_request_provider is NOT declared here: SCHEMA_SQL runs before + -- ensureCallLogsColumns() heals a legacy call_logs table, and a lineage that + -- predates the request_type column has none yet — the CREATE INDEX would abort + -- the whole schema exec with "no such column: request_type" and the server would + -- never boot. It is created next to the other request_type/combo indexes in + -- ensureCallLogsColumns() (db/schemaColumns.ts), after the columns exist. CREATE TABLE IF NOT EXISTS proxy_logs ( id TEXT PRIMARY KEY, diff --git a/src/lib/db/schemaColumns.ts b/src/lib/db/schemaColumns.ts index b288072dac..d0d7b42493 100644 --- a/src/lib/db/schemaColumns.ts +++ b/src/lib/db/schemaColumns.ts @@ -265,6 +265,12 @@ export function ensureCallLogsColumns(db: SqliteDatabase) { "CREATE INDEX IF NOT EXISTS idx_call_logs_requested_model ON call_logs(requested_model)" ); db.exec("CREATE INDEX IF NOT EXISTS idx_call_logs_request_type ON call_logs(request_type)"); + // #12832's provider-stats index. It lives here rather than in SCHEMA_SQL because + // SCHEMA_SQL runs before this healing pass: on a legacy call_logs table that + // predates `request_type` the CREATE INDEX aborts the whole schema exec. + db.exec( + "CREATE INDEX IF NOT EXISTS idx_cl_request_provider ON call_logs(request_type, provider)" + ); db.exec( "CREATE INDEX IF NOT EXISTS idx_cl_combo_target ON call_logs(combo_name, combo_execution_key, timestamp)" );