2026-06-02 13:25:44 +02:00
|
|
|
-- name: InsertAIGatewayKey :one
|
|
|
|
|
INSERT INTO ai_gateway_keys (id, name, secret_prefix, hashed_secret, created_at)
|
|
|
|
|
VALUES ($1, @name, $2, $3, NOW())
|
|
|
|
|
RETURNING id, name, secret_prefix, created_at;
|
|
|
|
|
|
|
|
|
|
-- name: ListAIGatewayKeys :many
|
2026-06-26 18:45:37 +02:00
|
|
|
SELECT id, name, secret_prefix, created_at, last_heartbeat_at
|
2026-06-02 13:25:44 +02:00
|
|
|
FROM ai_gateway_keys
|
|
|
|
|
ORDER BY created_at ASC;
|
|
|
|
|
|
|
|
|
|
-- name: DeleteAIGatewayKey :one
|
|
|
|
|
DELETE FROM ai_gateway_keys WHERE id = $1
|
2026-06-26 18:45:37 +02:00
|
|
|
RETURNING id, name, secret_prefix, created_at, last_heartbeat_at;
|
2026-06-26 18:16:01 +02:00
|
|
|
|
|
|
|
|
-- name: GetAIGatewayKeyByHashedSecret :one
|
|
|
|
|
-- Authenticates a standalone AI Gateway replica by its hashed key secret,
|
|
|
|
|
-- returning the matched key. The lookup is an exact match on a unique index,
|
|
|
|
|
-- so a returned row is itself proof the secret is valid.
|
|
|
|
|
SELECT *
|
|
|
|
|
FROM ai_gateway_keys
|
|
|
|
|
WHERE hashed_secret = $1;
|
|
|
|
|
|
2026-06-26 18:45:37 +02:00
|
|
|
-- name: UpdateAIGatewayKeyLastHeartbeatAt :execrows
|
|
|
|
|
-- Records heartbeat liveness for an active Gateway DRPC session. The database sets the
|
2026-06-26 18:16:01 +02:00
|
|
|
-- timestamp so it stays consistent regardless of clock drift between API
|
|
|
|
|
-- replicas.
|
|
|
|
|
UPDATE ai_gateway_keys
|
2026-06-26 18:45:37 +02:00
|
|
|
SET last_heartbeat_at = NOW()
|
2026-06-26 18:16:01 +02:00
|
|
|
WHERE id = $1;
|