Lists that were cut off by a fixed LIMIT, or could grow without bound, are paged by keyset: the cursor holds the sort key and an ID, so pages neither skip nor repeat items as others are added. The audit logs had a timestamp-only cursor that could skip entries with equal times. The API returns at most 100 items per list (limit takes up to 500) with next_cursor and prev_cursor, passed back as after and before. The console shows Newer/Older (or Previous/Next) links and To the start, without JavaScript. Paged: incidents (optionally of one monitor), a monitor's results and evidence, a checker's results, the audit logs, members, maintenance windows, firing Alertmanager alerts, the monitors API and the admin lists of status pages and organizations, which move to their own admin pages. A monitor's page shows its latest incidents and results and links to all of them. The dashboard caps every group at 50 of its own monitors with a link to a paged view of the group, and gains a search by name or target. Lists filtered by permission after reading may show fewer items on a page. Closes #116 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
36 lines
1.3 KiB
SQL
36 lines
1.3 KiB
SQL
-- name: AddMembership :exec
|
|
INSERT INTO memberships (org_id, user_id, is_owner) VALUES ($1, $2, $3);
|
|
|
|
-- name: RemoveMembership :execrows
|
|
DELETE FROM memberships WHERE org_id = $1 AND user_id = $2 AND NOT is_owner;
|
|
|
|
-- name: ListOrgMembers :many
|
|
SELECT u.id, u.email, u.display_name, m.is_owner, m.created_at AS joined_at
|
|
FROM memberships m
|
|
JOIN users u ON u.id = m.user_id
|
|
WHERE m.org_id = $1
|
|
ORDER BY u.email;
|
|
|
|
-- name: ListUserOrgs :many
|
|
SELECT o.id, o.slug, o.name, o.require_totp, m.is_owner
|
|
FROM memberships m
|
|
JOIN orgs o ON o.id = m.org_id
|
|
WHERE m.user_id = $1
|
|
ORDER BY o.name;
|
|
|
|
-- name: GetMembership :one
|
|
SELECT * FROM memberships WHERE org_id = $1 AND user_id = $2;
|
|
|
|
-- name: ListOrgMembersPage :many
|
|
-- By email, a page from a keyset cursor (see paging.go).
|
|
SELECT u.id, u.email, u.display_name, m.is_owner, m.created_at AS joined_at
|
|
FROM memberships m JOIN users u ON u.id = m.user_id
|
|
WHERE m.org_id = sqlc.arg(org_id)
|
|
AND (sqlc.narg(after_s)::text IS NULL OR (u.email::text, u.id) > (sqlc.narg(after_s), sqlc.narg(after_id)::uuid))
|
|
AND (sqlc.narg(before_s)::text IS NULL OR (u.email::text, u.id) < (sqlc.narg(before_s), sqlc.narg(before_id)::uuid))
|
|
ORDER BY
|
|
CASE WHEN sqlc.narg(before_s)::text IS NULL THEN u.email::text END,
|
|
CASE WHEN sqlc.narg(before_s)::text IS NULL THEN u.id END,
|
|
u.email::text DESC, u.id DESC
|
|
LIMIT sqlc.arg(max_rows);
|