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
32 lines
1.0 KiB
SQL
32 lines
1.0 KiB
SQL
-- name: InvitationOrg :one
|
|
SELECT coalesce(invitation_org(sqlc.arg(hash)::bytea), '00000000-0000-0000-0000-000000000000')::uuid AS org_id;
|
|
|
|
-- name: CreateInvitation :one
|
|
INSERT INTO invitations (org_id, email, role_id, token_hash, invited_by, expires_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
RETURNING *;
|
|
|
|
-- name: GetInvitationByHash :one
|
|
SELECT i.*, r.name AS role_name, o.name AS org_name, o.slug AS org_slug
|
|
FROM invitations i
|
|
JOIN roles r ON r.id = i.role_id
|
|
JOIN orgs o ON o.id = i.org_id
|
|
WHERE i.token_hash = $1;
|
|
|
|
-- name: ListPendingInvitations :many
|
|
SELECT i.id, i.email, i.expires_at, i.created_at, r.name AS role_name
|
|
FROM invitations i
|
|
JOIN roles r ON r.id = i.role_id
|
|
WHERE i.accepted_at IS NULL AND i.expires_at > now()
|
|
ORDER BY i.created_at DESC;
|
|
|
|
-- name: GetInvitation :one
|
|
SELECT * FROM invitations WHERE id = $1;
|
|
|
|
-- name: DeleteInvitation :execrows
|
|
DELETE FROM invitations WHERE id = $1;
|
|
|
|
-- name: MarkInvitationAccepted :execrows
|
|
UPDATE invitations SET accepted_at = now()
|
|
WHERE id = $1 AND accepted_at IS NULL AND expires_at > now();
|