fix(saas): add ::bigint cast to all SUM() aggregates for PG NUMERIC compat
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
PostgreSQL SUM() on bigint returns NUMERIC, causing sqlx decode errors when Rust expects i64/Option<i64>. Root cause: key_pool.rs select_best_key() token_count SUM was missing ::bigint, causing DATABASE_ERROR on every relay request. Fixed in 4 files: - relay/key_pool.rs: SUM(token_count) — root cause of relay failure - relay/service.rs: SUM(remaining_rpm) in sort_candidates_by_quota - account/handlers.rs: SUM(input/output_tokens) in dashboard stats - workers/aggregate_usage.rs: SUM(input/output_tokens) in aggregation
This commit is contained in:
@@ -56,8 +56,8 @@ async fn aggregate_single_account(db: &PgPool, account_id: &str) -> SaasResult<(
|
||||
.with_nanosecond(0).unwrap_or(now);
|
||||
|
||||
let aggregated: Option<(i64, i64, i64)> = sqlx::query_as(
|
||||
"SELECT COALESCE(SUM(input_tokens), 0), \
|
||||
COALESCE(SUM(output_tokens), 0), \
|
||||
"SELECT COALESCE(SUM(input_tokens), 0)::bigint, \
|
||||
COALESCE(SUM(output_tokens), 0)::bigint, \
|
||||
COUNT(*) \
|
||||
FROM usage_records \
|
||||
WHERE account_id = $1 AND created_at >= $2 AND status = 'success'"
|
||||
|
||||
Reference in New Issue
Block a user