ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / lint (pull_request) Successful in 6m54s
ci / test (pull_request) Successful in 12m15s
ci / build (pull_request) Successful in 11m0s
ci / image (pull_request) Successful in 4m23s
Outages open and close with their monitor; now people can say what is going on. An incident gets an optional title and updates, each with a status (investigating, identified, monitoring, resolved) and a Markdown message, shown on status pages or kept as an internal note. The incident shows the latest update's status, resolved once its monitor recovered. The console lists title and status and has a page per incident with its timeline (outage, updates, recovery) and, for incidents.write in the monitor's group, forms to post updates and set the title. Status pages show title, status and public updates. API: GET/PATCH /org/incidents/:id, POST and DELETE /org/incidents/:id/updates; the incident list carries title and status; the organization export includes the updates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
86 lines
3.5 KiB
SQL
86 lines
3.5 KiB
SQL
-- name: OwnedOrgs :many
|
|
-- Organizations user owns, with their member and owner counts.
|
|
SELECT o.id, o.slug, o.name,
|
|
(SELECT count(*) FROM memberships m2 WHERE m2.org_id = o.id)::bigint AS members,
|
|
(SELECT count(*) FROM memberships m3 WHERE m3.org_id = o.id AND m3.is_owner)::bigint AS owners
|
|
FROM orgs o JOIN memberships m ON m.org_id = o.id
|
|
WHERE m.user_id = $1 AND m.is_owner
|
|
ORDER BY o.name;
|
|
|
|
-- name: UserMemberships :many
|
|
SELECT o.id, o.slug, o.name, m.is_owner, m.created_at
|
|
FROM memberships m JOIN orgs o ON o.id = m.org_id
|
|
WHERE m.user_id = $1
|
|
ORDER BY o.name;
|
|
|
|
-- name: UserRoleNames :many
|
|
SELECT ra.org_id, r.name, ra.resource_type, ra.resource_id
|
|
FROM role_assignments ra JOIN roles r ON r.id = ra.role_id
|
|
WHERE ra.user_id = $1;
|
|
|
|
-- name: UserIdentities :many
|
|
SELECT p.name AS provider, i.org_id, i.subject, i.email, i.created_at, i.last_login_at
|
|
FROM user_identities i JOIN sso_providers p ON p.id = i.provider_id
|
|
WHERE i.user_id = $1;
|
|
|
|
-- name: UserTokens :many
|
|
SELECT org_id, name, prefix, permissions, expires_at, last_used_at, created_at
|
|
FROM api_tokens WHERE user_id = $1 ORDER BY created_at;
|
|
|
|
-- name: UserAuditEvents :many
|
|
-- Everything the user did, in any organization, and their own account log.
|
|
SELECT time, kind, org_id, action, target_id, details, status, coalesce(host(ip), '')::text AS ip,
|
|
coalesce(user_agent, '') AS user_agent
|
|
FROM audit_events WHERE actor_user_id = $1 ORDER BY time;
|
|
|
|
-- name: DeleteAccountAudit :exec
|
|
DELETE FROM audit_events WHERE kind = 'user' AND actor_user_id = $1;
|
|
|
|
-- name: ForgetAuditActor :exec
|
|
-- Keeps organization and platform entries readable as "deleted user" but
|
|
-- drops who it was.
|
|
UPDATE audit_events
|
|
SET actor_user_id = NULL, details = details || '{"actor_deleted": true}'
|
|
WHERE actor_user_id = $1;
|
|
|
|
-- name: ScrubAuditEmail :exec
|
|
UPDATE audit_events SET details = details - 'email' WHERE lower(details->>'email') = lower(sqlc.arg(email)::text);
|
|
|
|
-- name: DeleteInvitationsForEmail :exec
|
|
DELETE FROM invitations WHERE email = $1;
|
|
|
|
-- name: PurgeOrgCheckData :exec
|
|
SELECT purge_org_check_data($1);
|
|
|
|
-- name: DeleteOrgStorage :exec
|
|
DELETE FROM agent_storage WHERE owner = 'org:' || sqlc.arg(org_id)::uuid::text;
|
|
|
|
-- name: OrgMembersExport :many
|
|
SELECT u.id, u.email::text AS email, u.display_name, m.is_owner, m.created_at
|
|
FROM memberships m JOIN users u ON u.id = m.user_id
|
|
WHERE m.org_id = $1 ORDER BY u.email;
|
|
|
|
-- name: OrgAssignmentsExport :many
|
|
SELECT ra.user_id, r.name AS role, ra.resource_type, ra.resource_id
|
|
FROM role_assignments ra JOIN roles r ON r.id = ra.role_id
|
|
WHERE ra.org_id = $1;
|
|
|
|
-- name: OrgIncidentsExport :many
|
|
SELECT i.id, i.monitor_id, m.name AS monitor, i.started_at, i.resolved_at, i.cause, i.title, i.status
|
|
FROM incidents i LEFT JOIN monitors m ON m.id = i.monitor_id
|
|
WHERE i.org_id = $1 ORDER BY i.started_at;
|
|
|
|
-- name: OrgIncidentUpdatesExport :many
|
|
SELECT incident_id, status, message, public, created_at FROM incident_updates
|
|
WHERE org_id = $1 ORDER BY created_at;
|
|
|
|
-- name: OrgAuditExport :many
|
|
SELECT e.time, e.action, coalesce(u.email::text, '')::text AS actor, e.target_id, e.details, e.status,
|
|
coalesce(host(e.ip), '')::text AS ip
|
|
FROM audit_events e LEFT JOIN users u ON u.id = e.actor_user_id
|
|
WHERE e.kind = 'org' AND e.org_id = sqlc.arg(org_id)::uuid ORDER BY e.time;
|
|
|
|
-- name: OrgDailyStats :many
|
|
SELECT monitor_id, region, bucket::timestamptz AS day, total::bigint AS total, ok_count::bigint AS ok_count, avg_latency_ms::real AS avg_latency_ms
|
|
FROM check_results_1d WHERE org_id = $1 ORDER BY monitor_id, region, day;
|