fix(logging): auto-create client row to prevent FK constraint failure
INSERT into llm_requests was failing with FOREIGN KEY constraint (code 787) because client_id (e.g. 'client_sk-hobok') didn't exist in the clients table. Add INSERT OR IGNORE for the client row within the same transaction.
This commit is contained in:
@@ -63,6 +63,15 @@ impl RequestLogger {
|
||||
async fn insert_log(pool: &SqlitePool, log: RequestLog) -> Result<(), sqlx::Error> {
|
||||
let mut tx = pool.begin().await?;
|
||||
|
||||
// Ensure the client row exists (FK constraint requires it)
|
||||
sqlx::query(
|
||||
"INSERT OR IGNORE INTO clients (client_id, name, description) VALUES (?, ?, 'Auto-created from request')",
|
||||
)
|
||||
.bind(&log.client_id)
|
||||
.bind(&log.client_id)
|
||||
.execute(&mut *tx)
|
||||
.await?;
|
||||
|
||||
sqlx::query(
|
||||
r#"
|
||||
INSERT INTO llm_requests
|
||||
|
||||
Reference in New Issue
Block a user