Refs #82 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
21 lines
986 B
SQL
21 lines
986 B
SQL
-- name: TouchAgentInstance :exec
|
|
-- Writes at most once a minute per instance; agents poll far more often.
|
|
INSERT INTO agent_instances (id, agent_id, org_id, release)
|
|
VALUES ($1, $2, $3, $4)
|
|
ON CONFLICT (id) DO UPDATE SET release = EXCLUDED.release, last_seen_at = now()
|
|
WHERE agent_instances.last_seen_at < now() - interval '1 minute' OR agent_instances.release <> EXCLUDED.release;
|
|
|
|
-- name: AgentInstancesByID :many
|
|
SELECT i.id, i.agent_id, i.release, i.started_at, i.last_seen_at, i.org_id,
|
|
a.name AS agent_name, a.kind, r.id AS region_id, coalesce(r.name, '')::text AS region_name
|
|
FROM agent_instances i
|
|
JOIN agents a ON a.id = i.agent_id
|
|
LEFT JOIN regions r ON r.id = a.region_id
|
|
WHERE i.id = ANY (sqlc.arg(ids)::uuid[]);
|
|
|
|
-- name: SiblingInstances :many
|
|
-- Other instances of the same agent seen in the last day.
|
|
SELECT id, release, started_at, last_seen_at FROM agent_instances
|
|
WHERE agent_id = $1 AND last_seen_at > now() - interval '1 day'
|
|
ORDER BY last_seen_at DESC;
|