Files
uptimesebi/internal/store/queries/api_tokens.sql
T
Sebastian UnterschützandClaude Opus 5.5 ee09c497de feat(store): add roles, role assignments, api tokens and invitations
Built-in roles are seeded with fixed ids and are read-only for every org.
Existing non-owner members receive the Viewer role.

Refs #6, #7, #8, #9

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
2026-11-22 00:49:35 +01:00

28 lines
926 B
SQL

-- name: APITokenOrg :one
SELECT coalesce(api_token_org(sqlc.arg(hash)::bytea), '00000000-0000-0000-0000-000000000000')::uuid AS org_id;
-- name: GetAPITokenByHash :one
SELECT * FROM api_tokens WHERE token_hash = $1;
-- name: TouchAPIToken :exec
UPDATE api_tokens SET last_used_at = now()
WHERE id = $1 AND (last_used_at IS NULL OR last_used_at < now() - interval '1 minute');
-- name: CreateAPIToken :one
INSERT INTO api_tokens (org_id, user_id, name, token_hash, prefix, permissions, expires_at)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING *;
-- name: ListAPITokens :many
SELECT t.*, u.email AS user_email
FROM api_tokens t
JOIN users u ON u.id = t.user_id
WHERE t.org_id = $1 AND (sqlc.narg(user_id)::uuid IS NULL OR t.user_id = sqlc.narg(user_id))
ORDER BY t.created_at DESC;
-- name: GetAPIToken :one
SELECT * FROM api_tokens WHERE id = $1;
-- name: DeleteAPIToken :execrows
DELETE FROM api_tokens WHERE id = $1;