check_results has no row-level security because TimescaleDB refuses compression and continuous aggregates on such tables. Every results query takes org_id as a parameter, which a test enforces. Refs #10, #13 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
27 lines
970 B
SQL
27 lines
970 B
SQL
-- name: UpsertRegion :one
|
|
-- An empty name names a new region after its key and keeps an existing name.
|
|
INSERT INTO regions (key, name) VALUES (sqlc.arg(key), coalesce(nullif(sqlc.arg(name)::text, ''), sqlc.arg(key)))
|
|
ON CONFLICT (key) DO UPDATE SET name = CASE WHEN sqlc.arg(name)::text = '' THEN regions.name ELSE EXCLUDED.name END
|
|
RETURNING *;
|
|
|
|
-- name: ListRegions :many
|
|
SELECT * FROM regions ORDER BY key;
|
|
|
|
-- name: CreateAgent :one
|
|
INSERT INTO agents (org_id, kind, name, region, token_hash, prefix)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING *;
|
|
|
|
-- name: GetAgentByHash :one
|
|
SELECT * FROM agents WHERE token_hash = $1;
|
|
|
|
-- name: ListAgents :many
|
|
SELECT * FROM agents ORDER BY kind, region, name;
|
|
|
|
-- name: DeleteAgent :execrows
|
|
DELETE FROM agents WHERE id = $1;
|
|
|
|
-- name: TouchAgent :exec
|
|
UPDATE agents SET last_seen_at = now(), release = $2
|
|
WHERE id = $1 AND (last_seen_at IS NULL OR last_seen_at < now() - interval '30 seconds' OR release IS DISTINCT FROM $2);
|