-- 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();