fix(saas): SQL type cast fixes for E2E relay flow
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

- key_pool.rs: cast cooldown_until to timestamptz for comparison with NOW()
- key_pool.rs: cast request_count to bigint (INT4→INT8) for sqlx decoding
- service.rs: cast cooldown_until to timestamptz in quota sort query
- scheduler.rs: cast last_seen_at to timestamptz in device cleanup
- totp.rs: use DateTime<Utc> instead of rfc3339 string for updated_at
This commit is contained in:
iven
2026-04-07 22:24:19 +08:00
parent ca0e537682
commit f9303ae0c3
4 changed files with 7 additions and 7 deletions

View File

@@ -226,7 +226,7 @@ pub async fn verify_totp(
encrypt_totp_secret(&secret, &enc_key)?
};
let now_ts = chrono::Utc::now().to_rfc3339();
let now_ts = chrono::Utc::now();
sqlx::query("UPDATE accounts SET totp_enabled = true, totp_secret = $1, updated_at = $2 WHERE id = $3")
.bind(&final_secret)
.bind(&now_ts)
@@ -260,7 +260,7 @@ pub async fn disable_totp(
}
// 清除 TOTP
let now = chrono::Utc::now().to_rfc3339();
let now = chrono::Utc::now();
sqlx::query("UPDATE accounts SET totp_enabled = false, totp_secret = NULL, updated_at = $1 WHERE id = $2")
.bind(&now)
.bind(&ctx.account_id)

View File

@@ -45,11 +45,11 @@ pub async fn select_best_key(db: &PgPool, provider_id: &str, enc_key: &[u8; 32])
let rows: Vec<(String, String, i32, Option<i64>, Option<i64>, Option<i64>, Option<i64>)> =
sqlx::query_as(
"SELECT pk.id, pk.key_value, pk.priority, pk.max_rpm, pk.max_tpm,
uw.request_count, uw.token_count
uw.request_count::bigint, uw.token_count
FROM provider_keys pk
LEFT JOIN key_usage_window uw ON pk.id = uw.key_id AND uw.window_minute = $1
WHERE pk.provider_id = $2 AND pk.is_active = TRUE
AND (pk.cooldown_until IS NULL OR pk.cooldown_until <= $3)
AND (pk.cooldown_until IS NULL OR pk.cooldown_until::timestamptz <= $3)
ORDER BY pk.priority ASC, pk.last_used_at ASC NULLS FIRST"
).bind(&current_minute).bind(provider_id).bind(&now).fetch_all(db).await?;
@@ -95,7 +95,7 @@ pub async fn select_best_key(db: &PgPool, provider_id: &str, enc_key: &[u8; 32])
// 检查是否有冷却中的 Key返回预计等待时间
let cooldown_row: Option<(String,)> = sqlx::query_as(
"SELECT cooldown_until::TEXT FROM provider_keys
WHERE provider_id = $1 AND is_active = TRUE AND cooldown_until IS NOT NULL AND cooldown_until > $2
WHERE provider_id = $1 AND is_active = TRUE AND cooldown_until IS NOT NULL AND cooldown_until::timestamptz > $2
ORDER BY cooldown_until ASC
LIMIT 1"
).bind(provider_id).bind(&now).fetch_optional(db).await?;

View File

@@ -653,7 +653,7 @@ pub async fn sort_candidates_by_quota(
AND uw.window_minute = to_char(date_trunc('minute', NOW()), 'YYYY-MM-DDTHH24:MI')
WHERE pk.provider_id = ANY($1)
AND pk.is_active = TRUE
AND (pk.cooldown_until IS NULL OR pk.cooldown_until <= NOW())
AND (pk.cooldown_until IS NULL OR pk.cooldown_until::timestamptz <= NOW())
GROUP BY pk.provider_id
"#,
)

View File

@@ -89,7 +89,7 @@ pub fn start_db_cleanup_tasks(db: PgPool) {
loop {
interval.tick().await;
match sqlx::query(
"DELETE FROM devices WHERE last_seen_at < $1"
"DELETE FROM devices WHERE last_seen_at::timestamptz < $1"
)
.bind({
let cutoff = (chrono::Utc::now() - chrono::Duration::days(90));