feat: page long and truncated lists
ci / image (pull_request) Successful in 3m18s
ci / build (pull_request) Successful in 8m38s
ci / test (pull_request) Successful in 12m6s
ci / lint (pull_request) Successful in 15m0s

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
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 21:40:25 +01:00
1 parent 98fb5d3a82
commit d7c5cd711e
63 files changed
+5427 -3041

No files matched your search

+69
View File
@@ -185,6 +185,75 @@ func (q *Queries) FiringAlerts(ctx context.Context, arg FiringAlertsParams) ([]F
return items, nil
}
const firingAlertsPage = `-- name: FiringAlertsPage :many
SELECT fingerprint, labels, annotations, starts_at, generator_url, updated_at
FROM alertmanager_alerts
WHERE org_id = $1 AND status = 'firing' AND updated_at > $2
AND ($3::timestamptz IS NULL OR (starts_at, fingerprint) < ($3, $4::text))
AND ($5::timestamptz IS NULL OR (starts_at, fingerprint) > ($5, $6::text))
ORDER BY
CASE WHEN $5::timestamptz IS NULL THEN starts_at END DESC,
CASE WHEN $5::timestamptz IS NULL THEN fingerprint END DESC,
starts_at, fingerprint
LIMIT $7
`
type FiringAlertsPageParams struct {
OrgID uuid.UUID
Since time.Time
AfterT *time.Time
AfterS *string
BeforeT *time.Time
BeforeS *string
MaxRows int32
}
type FiringAlertsPageRow struct {
Fingerprint string
Labels []byte
Annotations []byte
StartsAt time.Time
GeneratorUrl string
UpdatedAt time.Time
}
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
// whose string key is the fingerprint.
func (q *Queries) FiringAlertsPage(ctx context.Context, arg FiringAlertsPageParams) ([]FiringAlertsPageRow, error) {
rows, err := q.db.Query(ctx, firingAlertsPage,
arg.OrgID,
arg.Since,
arg.AfterT,
arg.AfterS,
arg.BeforeT,
arg.BeforeS,
arg.MaxRows,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []FiringAlertsPageRow{}
for rows.Next() {
var i FiringAlertsPageRow
if err := rows.Scan(
&i.Fingerprint,
&i.Labels,
&i.Annotations,
&i.StartsAt,
&i.GeneratorUrl,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const latestResultForMonitor = `-- name: LatestResultForMonitor :one
SELECT ok, coalesce(error, '')::text AS error FROM check_results
WHERE org_id = $1 AND monitor_id = $2 AND time > now() - interval '2 days'
+21 -11
View File
@@ -59,17 +59,24 @@ LEFT JOIN users u ON u.id = e.actor_user_id
WHERE e.kind = $1
AND ($2::uuid IS NULL OR e.org_id = $2)
AND ($3::uuid IS NULL OR e.actor_user_id = $3)
AND ($4::timestamptz IS NULL OR e.time < $4)
ORDER BY e.time DESC
LIMIT $5
AND ($4::timestamptz IS NULL OR (e.time, e.id) < ($4, $5::uuid))
AND ($6::timestamptz IS NULL OR (e.time, e.id) > ($6, $7::uuid))
ORDER BY
CASE WHEN $6::timestamptz IS NULL THEN e.time END DESC,
CASE WHEN $6::timestamptz IS NULL THEN e.id END DESC,
e.time, e.id
LIMIT $8
`
type ListAuditEventsParams struct {
Kind string
OrgID *uuid.UUID
Actor *uuid.UUID
Before *time.Time
MaxRows int32
Kind string
OrgID *uuid.UUID
Actor *uuid.UUID
AfterT *time.Time
AfterID *uuid.UUID
BeforeT *time.Time
BeforeID *uuid.UUID
MaxRows int32
}
type ListAuditEventsRow struct {
@@ -90,14 +97,17 @@ type ListAuditEventsRow struct {
ActorName string
}
// Newest first, paged by time. kind narrows to one kind; the row policy
// already limits what the scope can see.
// Newest first, a page from a keyset cursor (see paging.go). kind narrows
// to one kind; the row policy already limits what the scope can see.
func (q *Queries) ListAuditEvents(ctx context.Context, arg ListAuditEventsParams) ([]ListAuditEventsRow, error) {
rows, err := q.db.Query(ctx, listAuditEvents,
arg.Kind,
arg.OrgID,
arg.Actor,
arg.Before,
arg.AfterT,
arg.AfterID,
arg.BeforeT,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
+102 -57
View File
@@ -343,6 +343,82 @@ func (q *Queries) LatestResultsForMonitor(ctx context.Context, arg LatestResults
return items, nil
}
const listResults = `-- name: ListResults :many
SELECT time, region, ok, latency_ms, status_code, error, checker_id,
(region || '|' || checker_id::text)::text AS position
FROM check_results
WHERE org_id = $1 AND monitor_id = $2
AND ($3::timestamptz IS NULL
OR time <= $3 AND (time, region || '|' || checker_id::text) < ($3, $4::text))
AND ($5::timestamptz IS NULL
OR time >= $5 AND (time, region || '|' || checker_id::text) > ($5, $6::text))
ORDER BY
CASE WHEN $5::timestamptz IS NULL THEN time END DESC,
CASE WHEN $5::timestamptz IS NULL THEN region || '|' || checker_id::text END DESC,
time, region || '|' || checker_id::text
LIMIT $7
`
type ListResultsParams struct {
OrgID uuid.UUID
MonitorID uuid.UUID
AfterT *time.Time
AfterS *string
BeforeT *time.Time
BeforeS *string
MaxRows int32
}
type ListResultsRow struct {
Time time.Time
Region string
Ok bool
LatencyMs *int32
StatusCode *int32
Error *string
CheckerID uuid.UUID
Position string
}
// A monitor's results newest first, a page from a keyset cursor (see
// paging.go) whose string key is region and checker.
func (q *Queries) ListResults(ctx context.Context, arg ListResultsParams) ([]ListResultsRow, error) {
rows, err := q.db.Query(ctx, listResults,
arg.OrgID,
arg.MonitorID,
arg.AfterT,
arg.AfterS,
arg.BeforeT,
arg.BeforeS,
arg.MaxRows,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListResultsRow{}
for rows.Next() {
var i ListResultsRow
if err := rows.Scan(
&i.Time,
&i.Region,
&i.Ok,
&i.LatencyMs,
&i.StatusCode,
&i.Error,
&i.CheckerID,
&i.Position,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const rangeBuckets = `-- name: RangeBuckets :many
SELECT monitor_id, time_bucket($2::text::interval, time)::timestamptz AS bucket,
count(*)::bigint AS total, count(*) FILTER (WHERE ok)::bigint AS ok_count,
@@ -517,58 +593,6 @@ func (q *Queries) RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourly
return items, nil
}
const recentResults = `-- name: RecentResults :many
SELECT time, region, ok, latency_ms, status_code, error, checker_id
FROM check_results
WHERE org_id = $1 AND monitor_id = $2 AND time > $3
ORDER BY time DESC
LIMIT 500
`
type RecentResultsParams struct {
OrgID uuid.UUID
MonitorID uuid.UUID
Time time.Time
}
type RecentResultsRow struct {
Time time.Time
Region string
Ok bool
LatencyMs *int32
StatusCode *int32
Error *string
CheckerID uuid.UUID
}
func (q *Queries) RecentResults(ctx context.Context, arg RecentResultsParams) ([]RecentResultsRow, error) {
rows, err := q.db.Query(ctx, recentResults, arg.OrgID, arg.MonitorID, arg.Time)
if err != nil {
return nil, err
}
defer rows.Close()
items := []RecentResultsRow{}
for rows.Next() {
var i RecentResultsRow
if err := rows.Scan(
&i.Time,
&i.Region,
&i.Ok,
&i.LatencyMs,
&i.StatusCode,
&i.Error,
&i.CheckerID,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const regionBuckets = `-- name: RegionBuckets :many
SELECT region, time_bucket($2::text::interval, time)::timestamptz AS bucket,
count(*)::bigint AS total, count(*) FILTER (WHERE ok)::bigint AS ok_count
@@ -732,14 +756,26 @@ func (q *Queries) RegionBucketsHourly(ctx context.Context, arg RegionBucketsHour
const resultsByChecker = `-- name: ResultsByChecker :many
SELECT r.time, r.monitor_id, r.region, r.ok, r.latency_ms, r.status_code, r.error
FROM check_results r
WHERE r.org_id = $1 AND r.checker_id = $2 AND r.time > now() - interval '1 day'
ORDER BY r.time DESC
LIMIT 50
WHERE r.org_id = $1 AND r.checker_id = $2
AND ($3::timestamptz IS NULL
OR r.time <= $3 AND (r.time, r.monitor_id::text || '|' || r.region) < ($3, $4::text))
AND ($5::timestamptz IS NULL
OR r.time >= $5 AND (r.time, r.monitor_id::text || '|' || r.region) > ($5, $6::text))
ORDER BY
CASE WHEN $5::timestamptz IS NULL THEN r.time END DESC,
CASE WHEN $5::timestamptz IS NULL THEN r.monitor_id::text || '|' || r.region END DESC,
r.time, r.monitor_id::text || '|' || r.region
LIMIT $7
`
type ResultsByCheckerParams struct {
OrgID uuid.UUID
CheckerID uuid.UUID
AfterT *time.Time
AfterS *string
BeforeT *time.Time
BeforeS *string
MaxRows int32
}
type ResultsByCheckerRow struct {
@@ -752,9 +788,18 @@ type ResultsByCheckerRow struct {
Error *string
}
// The organization's latest results run by one checker instance.
// The organization's results run by one checker instance, newest first, a
// page from a keyset cursor whose string key is monitor and region.
func (q *Queries) ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error) {
rows, err := q.db.Query(ctx, resultsByChecker, arg.OrgID, arg.CheckerID)
rows, err := q.db.Query(ctx, resultsByChecker,
arg.OrgID,
arg.CheckerID,
arg.AfterT,
arg.AfterS,
arg.BeforeT,
arg.BeforeS,
arg.MaxRows,
)
if err != nil {
return nil, err
}
+64 -3
View File
@@ -27,6 +27,44 @@ func (q *Queries) DeleteSuccessEvidence(ctx context.Context, arg DeleteSuccessEv
return err
}
const evidenceBetween = `-- name: EvidenceBetween :many
SELECT id, region, time FROM check_evidence
WHERE monitor_id = $1 AND time BETWEEN $2 AND $3
`
type EvidenceBetweenParams struct {
MonitorID uuid.UUID
Since time.Time
Until time.Time
}
type EvidenceBetweenRow struct {
ID uuid.UUID
Region string
Time time.Time
}
// Evidence of a monitor in a time span, to link results to it.
func (q *Queries) EvidenceBetween(ctx context.Context, arg EvidenceBetweenParams) ([]EvidenceBetweenRow, error) {
rows, err := q.db.Query(ctx, evidenceBetween, arg.MonitorID, arg.Since, arg.Until)
if err != nil {
return nil, err
}
defer rows.Close()
items := []EvidenceBetweenRow{}
for rows.Next() {
var i EvidenceBetweenRow
if err := rows.Scan(&i.ID, &i.Region, &i.Time); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getEvidence = `-- name: GetEvidence :one
SELECT id, org_id, monitor_id, region, checker_id, time, ok, status_code, error, evidence FROM check_evidence WHERE id = $1 AND monitor_id = $2
`
@@ -112,9 +150,24 @@ func (q *Queries) LastFailureEvidence(ctx context.Context, arg LastFailureEviden
const listEvidence = `-- name: ListEvidence :many
SELECT id, region, checker_id, time, ok, status_code, error FROM check_evidence
WHERE monitor_id = $1
ORDER BY time DESC LIMIT 100
AND ($2::timestamptz IS NULL OR (time, id) < ($2, $3::uuid))
AND ($4::timestamptz IS NULL OR (time, id) > ($4, $5::uuid))
ORDER BY
CASE WHEN $4::timestamptz IS NULL THEN time END DESC,
CASE WHEN $4::timestamptz IS NULL THEN id END DESC,
time, id
LIMIT $6
`
type ListEvidenceParams struct {
MonitorID uuid.UUID
AfterT *time.Time
AfterID *uuid.UUID
BeforeT *time.Time
BeforeID *uuid.UUID
MaxRows int32
}
type ListEvidenceRow struct {
ID uuid.UUID
Region string
@@ -125,8 +178,16 @@ type ListEvidenceRow struct {
Error *string
}
func (q *Queries) ListEvidence(ctx context.Context, monitorID uuid.UUID) ([]ListEvidenceRow, error) {
rows, err := q.db.Query(ctx, listEvidence, monitorID)
// Newest first, a page from a keyset cursor (see paging.go).
func (q *Queries) ListEvidence(ctx context.Context, arg ListEvidenceParams) ([]ListEvidenceRow, error) {
rows, err := q.db.Query(ctx, listEvidence,
arg.MonitorID,
arg.AfterT,
arg.AfterID,
arg.BeforeT,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
return nil, err
}
+28 -35
View File
@@ -245,10 +245,25 @@ const listIncidents = `-- name: ListIncidents :many
SELECT i.id, i.org_id, i.monitor_id, i.started_at, i.resolved_at, i.cause, m.name AS monitor_name
FROM incidents i
JOIN monitors m ON m.id = i.monitor_id
ORDER BY i.started_at DESC
LIMIT 200
WHERE ($1::uuid IS NULL OR i.monitor_id = $1)
AND ($2::timestamptz IS NULL OR (i.started_at, i.id) < ($2, $3::uuid))
AND ($4::timestamptz IS NULL OR (i.started_at, i.id) > ($4, $5::uuid))
ORDER BY
CASE WHEN $4::timestamptz IS NULL THEN i.started_at END DESC,
CASE WHEN $4::timestamptz IS NULL THEN i.id END DESC,
i.started_at, i.id
LIMIT $6
`
type ListIncidentsParams struct {
MonitorID *uuid.UUID
AfterT *time.Time
AfterID *uuid.UUID
BeforeT *time.Time
BeforeID *uuid.UUID
MaxRows int32
}
type ListIncidentsRow struct {
ID uuid.UUID
OrgID uuid.UUID
@@ -259,8 +274,17 @@ type ListIncidentsRow struct {
MonitorName string
}
func (q *Queries) ListIncidents(ctx context.Context) ([]ListIncidentsRow, error) {
rows, err := q.db.Query(ctx, listIncidents)
// Newest first, a page from a keyset cursor (see paging.go); optionally of
// one monitor.
func (q *Queries) ListIncidents(ctx context.Context, arg ListIncidentsParams) ([]ListIncidentsRow, error) {
rows, err := q.db.Query(ctx, listIncidents,
arg.MonitorID,
arg.AfterT,
arg.AfterID,
arg.BeforeT,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
return nil, err
}
@@ -321,37 +345,6 @@ func (q *Queries) MarkNotificationSent(ctx context.Context, id uuid.UUID) error
return err
}
const monitorIncidents = `-- name: MonitorIncidents :many
SELECT id, org_id, monitor_id, started_at, resolved_at, cause FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20
`
func (q *Queries) MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error) {
rows, err := q.db.Query(ctx, monitorIncidents, monitorID)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Incident{}
for rows.Next() {
var i Incident
if err := rows.Scan(
&i.ID,
&i.OrgID,
&i.MonitorID,
&i.StartedAt,
&i.ResolvedAt,
&i.Cause,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const notificationDetails = `-- name: NotificationDetails :many
SELECT n.id, n.org_id, n.event, n.attempts,
c.type AS channel_type, c.config AS channel_config, c.id AS channel_id,
+25 -8
View File
@@ -29,16 +29,25 @@ LEFT JOIN LATERAL (
FROM memberships m JOIN users u ON u.id = m.user_id
WHERE m.org_id = o.id AND m.is_owner ORDER BY m.created_at LIMIT 1
) ow ON true
WHERE $1::text = ''
WHERE ($1::text = ''
OR o.name ILIKE '%' || $1 || '%' OR o.slug::text ILIKE '%' || $1 || '%'
OR coalesce(ow.email::text, '') ILIKE '%' || $1 || '%'
ORDER BY o.created_at DESC
LIMIT $2
OR coalesce(ow.email::text, '') ILIKE '%' || $1 || '%')
AND ($2::timestamptz IS NULL OR (o.created_at, o.id) < ($2, $3::uuid))
AND ($4::timestamptz IS NULL OR (o.created_at, o.id) > ($4, $5::uuid))
ORDER BY
CASE WHEN $4::timestamptz IS NULL THEN o.created_at END DESC,
CASE WHEN $4::timestamptz IS NULL THEN o.id END DESC,
o.created_at, o.id
LIMIT $6
`
type AdminListOrgsParams struct {
Search string
MaxRows int32
Search string
AfterT *time.Time
AfterID *uuid.UUID
BeforeT *time.Time
BeforeID *uuid.UUID
MaxRows int32
}
type AdminListOrgsRow struct {
@@ -64,9 +73,17 @@ type AdminListOrgsRow struct {
}
// System scope: organizations with their usage, limit overrides and owner,
// newest first, matching search in name, slug or owner email.
// matching search in name, slug or owner email; newest first, a page from a
// keyset cursor.
func (q *Queries) AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([]AdminListOrgsRow, error) {
rows, err := q.db.Query(ctx, adminListOrgs, arg.Search, arg.MaxRows)
rows, err := q.db.Query(ctx, adminListOrgs,
arg.Search,
arg.AfterT,
arg.AfterID,
arg.BeforeT,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
return nil, err
}
+61
View File
@@ -168,6 +168,67 @@ func (q *Queries) ListMaintenance(ctx context.Context) ([]MaintenanceWindow, err
return items, nil
}
const listMaintenancePage = `-- name: ListMaintenancePage :many
SELECT id, org_id, title, description, starts_at, duration_seconds, time_zone, recurrence, every, weekdays, until, created_at, updated_at FROM maintenance_windows
WHERE true
AND ($1::timestamptz IS NULL OR (starts_at, id) < ($1, $2::uuid))
AND ($3::timestamptz IS NULL OR (starts_at, id) > ($3, $4::uuid))
ORDER BY
CASE WHEN $3::timestamptz IS NULL THEN starts_at END DESC,
CASE WHEN $3::timestamptz IS NULL THEN id END DESC,
starts_at, id
LIMIT $5
`
type ListMaintenancePageParams struct {
AfterT *time.Time
AfterID *uuid.UUID
BeforeT *time.Time
BeforeID *uuid.UUID
MaxRows int32
}
// Latest start first, a page from a keyset cursor (see paging.go).
func (q *Queries) ListMaintenancePage(ctx context.Context, arg ListMaintenancePageParams) ([]MaintenanceWindow, error) {
rows, err := q.db.Query(ctx, listMaintenancePage,
arg.AfterT,
arg.AfterID,
arg.BeforeT,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []MaintenanceWindow{}
for rows.Next() {
var i MaintenanceWindow
if err := rows.Scan(
&i.ID,
&i.OrgID,
&i.Title,
&i.Description,
&i.StartsAt,
&i.DurationSeconds,
&i.TimeZone,
&i.Recurrence,
&i.Every,
&i.Weekdays,
&i.Until,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listMaintenanceTargets = `-- name: ListMaintenanceTargets :many
SELECT window_id, org_id, monitor_id, group_id FROM maintenance_targets
`
+64
View File
@@ -90,6 +90,70 @@ func (q *Queries) ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOr
return items, nil
}
const listOrgMembersPage = `-- name: ListOrgMembersPage :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
AND ($2::text IS NULL OR (u.email::text, u.id) > ($2, $3::uuid))
AND ($4::text IS NULL OR (u.email::text, u.id) < ($4, $5::uuid))
ORDER BY
CASE WHEN $4::text IS NULL THEN u.email::text END,
CASE WHEN $4::text IS NULL THEN u.id END,
u.email::text DESC, u.id DESC
LIMIT $6
`
type ListOrgMembersPageParams struct {
OrgID uuid.UUID
AfterS *string
AfterID *uuid.UUID
BeforeS *string
BeforeID *uuid.UUID
MaxRows int32
}
type ListOrgMembersPageRow struct {
ID uuid.UUID
Email string
DisplayName string
IsOwner bool
JoinedAt time.Time
}
// By email, a page from a keyset cursor (see paging.go).
func (q *Queries) ListOrgMembersPage(ctx context.Context, arg ListOrgMembersPageParams) ([]ListOrgMembersPageRow, error) {
rows, err := q.db.Query(ctx, listOrgMembersPage,
arg.OrgID,
arg.AfterS,
arg.AfterID,
arg.BeforeS,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []ListOrgMembersPageRow{}
for rows.Next() {
var i ListOrgMembersPageRow
if err := rows.Scan(
&i.ID,
&i.Email,
&i.DisplayName,
&i.IsOwner,
&i.JoinedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listUserOrgs = `-- name: ListUserOrgs :many
SELECT o.id, o.slug, o.name, o.require_totp, m.is_owner
FROM memberships m
+23 -7
View File
@@ -31,13 +31,22 @@ WHERE (p.published OR p.suspended_at IS NOT NULL OR o.suspended_at IS NOT NULL)
OR coalesce(p.custom_domain::text, '') ILIKE '%' || $1 || '%'
OR o.name ILIKE '%' || $1 || '%' OR o.slug::text ILIKE '%' || $1 || '%'
OR coalesce(ow.email::text, '') ILIKE '%' || $1 || '%')
ORDER BY p.created_at DESC
LIMIT $2
AND ($2::timestamptz IS NULL OR (p.created_at, p.id) < ($2, $3::uuid))
AND ($4::timestamptz IS NULL OR (p.created_at, p.id) > ($4, $5::uuid))
ORDER BY
CASE WHEN $4::timestamptz IS NULL THEN p.created_at END DESC,
CASE WHEN $4::timestamptz IS NULL THEN p.id END DESC,
p.created_at, p.id
LIMIT $6
`
type AdminListStatusPagesParams struct {
Search string
MaxRows int32
Search string
AfterT *time.Time
AfterID *uuid.UUID
BeforeT *time.Time
BeforeID *uuid.UUID
MaxRows int32
}
type AdminListStatusPagesRow struct {
@@ -63,10 +72,17 @@ type AdminListStatusPagesRow struct {
}
// System scope: public status pages and suspended ones, with their
// organization and its owner, newest first, matching search in title,
// slug, domain, organization or owner email.
// organization and its owner, matching search in title, slug, domain,
// organization or owner email; newest first, a page from a keyset cursor.
func (q *Queries) AdminListStatusPages(ctx context.Context, arg AdminListStatusPagesParams) ([]AdminListStatusPagesRow, error) {
rows, err := q.db.Query(ctx, adminListStatusPages, arg.Search, arg.MaxRows)
rows, err := q.db.Query(ctx, adminListStatusPages,
arg.Search,
arg.AfterT,
arg.AfterID,
arg.BeforeT,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
return nil, err
}
+61
View File
@@ -227,6 +227,67 @@ func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
return items, nil
}
const listMonitorsPage = `-- name: ListMonitorsPage :many
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors
WHERE true
AND ($1::text IS NULL OR (name, id) > ($1, $2::uuid))
AND ($3::text IS NULL OR (name, id) < ($3, $4::uuid))
ORDER BY
CASE WHEN $3::text IS NULL THEN name END,
CASE WHEN $3::text IS NULL THEN id END,
name DESC, id DESC
LIMIT $5
`
type ListMonitorsPageParams struct {
AfterS *string
AfterID *uuid.UUID
BeforeS *string
BeforeID *uuid.UUID
MaxRows int32
}
// By name, a page from a keyset cursor (see paging.go).
func (q *Queries) ListMonitorsPage(ctx context.Context, arg ListMonitorsPageParams) ([]Monitor, error) {
rows, err := q.db.Query(ctx, listMonitorsPage,
arg.AfterS,
arg.AfterID,
arg.BeforeS,
arg.BeforeID,
arg.MaxRows,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []Monitor{}
for rows.Next() {
var i Monitor
if err := rows.Scan(
&i.ID,
&i.OrgID,
&i.Name,
&i.Type,
&i.Target,
&i.IntervalSeconds,
&i.TimeoutMs,
&i.Config,
&i.Enabled,
&i.CreatedAt,
&i.UpdatedAt,
&i.Confirmations,
&i.GroupID,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const monitorRegions = `-- name: MonitorRegions :many
SELECT region_id FROM monitor_regions WHERE monitor_id = $1 ORDER BY region_id
`
+27 -10
View File
@@ -20,11 +20,12 @@ type Querier interface {
AddMonitorRegion(ctx context.Context, arg AddMonitorRegionParams) error
AddStatusPageMonitor(ctx context.Context, arg AddStatusPageMonitorParams) error
// System scope: organizations with their usage, limit overrides and owner,
// newest first, matching search in name, slug or owner email.
// matching search in name, slug or owner email; newest first, a page from a
// keyset cursor.
AdminListOrgs(ctx context.Context, arg AdminListOrgsParams) ([]AdminListOrgsRow, error)
// System scope: public status pages and suspended ones, with their
// organization and its owner, newest first, matching search in title,
// slug, domain, organization or owner email.
// organization and its owner, matching search in title, slug, domain,
// organization or owner email; newest first, a page from a keyset cursor.
AdminListStatusPages(ctx context.Context, arg AdminListStatusPagesParams) ([]AdminListStatusPagesRow, error)
AgentInstancesByID(ctx context.Context, ids []uuid.UUID) ([]AgentInstancesByIDRow, error)
// System scope: enabled alertmanager monitors of org, with when they last
@@ -102,11 +103,16 @@ type Querier interface {
EnqueueNotification(ctx context.Context, arg EnqueueNotificationParams) error
// An empty name names a new region after its key and keeps an existing name.
EnsurePlatformRegion(ctx context.Context, arg EnsurePlatformRegionParams) (Region, error)
// Evidence of a monitor in a time span, to link results to it.
EvidenceBetween(ctx context.Context, arg EvidenceBetweenParams) ([]EvidenceBetweenRow, error)
// System scope: resolves a request to a page by verified custom domain or
// by slug.
FindPublishedPage(ctx context.Context, arg FindPublishedPageParams) (StatusPage, error)
// Alerts of org that fire and were repeated within the stale period.
FiringAlerts(ctx context.Context, arg FiringAlertsParams) ([]FiringAlertsRow, error)
// FiringAlerts newest first, a page from a keyset cursor (see paging.go)
// whose string key is the fingerprint.
FiringAlertsPage(ctx context.Context, arg FiringAlertsPageParams) ([]FiringAlertsPageRow, error)
// When each monitor and region first reported, to the day.
FirstDataDaily(ctx context.Context, orgID uuid.UUID) ([]FirstDataDailyRow, error)
// When each monitor and region first reported since $2, exactly. Used for
@@ -171,24 +177,36 @@ type Querier interface {
ListAlertGroups(ctx context.Context) ([]ListAlertGroupsRow, error)
ListAlertmanagerReceivers(ctx context.Context) ([]ListAlertmanagerReceiversRow, error)
ListAssignments(ctx context.Context, orgID uuid.UUID) ([]ListAssignmentsRow, error)
// Newest first, paged by time. kind narrows to one kind; the row policy
// already limits what the scope can see.
// Newest first, a page from a keyset cursor (see paging.go). kind narrows
// to one kind; the row policy already limits what the scope can see.
ListAuditEvents(ctx context.Context, arg ListAuditEventsParams) ([]ListAuditEventsRow, error)
ListChannels(ctx context.Context) ([]NotificationChannel, error)
// System scope: every enabled monitor with its regions, for reconciling the
// schedule.
ListEnabledMonitorsForSchedule(ctx context.Context) ([]ListEnabledMonitorsForScheduleRow, error)
ListEnabledSSOProviders(ctx context.Context) ([]ListEnabledSSOProvidersRow, error)
ListEvidence(ctx context.Context, monitorID uuid.UUID) ([]ListEvidenceRow, error)
// Newest first, a page from a keyset cursor (see paging.go).
ListEvidence(ctx context.Context, arg ListEvidenceParams) ([]ListEvidenceRow, error)
ListGroups(ctx context.Context) ([]MonitorGroup, error)
ListIncidents(ctx context.Context) ([]ListIncidentsRow, error)
// Newest first, a page from a keyset cursor (see paging.go); optionally of
// one monitor.
ListIncidents(ctx context.Context, arg ListIncidentsParams) ([]ListIncidentsRow, error)
ListMaintenance(ctx context.Context) ([]MaintenanceWindow, error)
// Latest start first, a page from a keyset cursor (see paging.go).
ListMaintenancePage(ctx context.Context, arg ListMaintenancePageParams) ([]MaintenanceWindow, error)
ListMaintenanceTargets(ctx context.Context) ([]MaintenanceTarget, error)
ListMonitors(ctx context.Context) ([]Monitor, error)
// By name, a page from a keyset cursor (see paging.go).
ListMonitorsPage(ctx context.Context, arg ListMonitorsPageParams) ([]Monitor, error)
ListOrgMembers(ctx context.Context, orgID uuid.UUID) ([]ListOrgMembersRow, error)
// By email, a page from a keyset cursor (see paging.go).
ListOrgMembersPage(ctx context.Context, arg ListOrgMembersPageParams) ([]ListOrgMembersPageRow, error)
ListOrgs(ctx context.Context) ([]Org, error)
ListPendingInvitations(ctx context.Context) ([]ListPendingInvitationsRow, error)
ListPlatformRegions(ctx context.Context) ([]Region, error)
// A monitor's results newest first, a page from a keyset cursor (see
// paging.go) whose string key is region and checker.
ListResults(ctx context.Context, arg ListResultsParams) ([]ListResultsRow, error)
ListRoles(ctx context.Context) ([]Role, error)
ListSSOProviders(ctx context.Context) ([]SsoProvider, error)
ListStatusPageGroups(ctx context.Context, pageID uuid.UUID) ([]StatusPageGroup, error)
@@ -213,7 +231,6 @@ type Querier interface {
MemberGrants(ctx context.Context, arg MemberGrantsParams) ([]MemberGrantsRow, error)
MonitorAlertGroups(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
MonitorAlertRoutes(ctx context.Context, monitorID uuid.UUID) ([]MonitorAlertRoutesRow, error)
MonitorIncidents(ctx context.Context, monitorID uuid.UUID) ([]Incident, error)
MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uuid.UUID, error)
// System scope: monitors to hand to a checker of region, skipping ones that
// were disabled, deleted or moved out of the region since dispatch. An
@@ -251,7 +268,6 @@ type Querier interface {
RangeBucketsDaily(ctx context.Context, arg RangeBucketsDailyParams) ([]RangeBucketsDailyRow, error)
// The hourly aggregate rebucketed by width, for ranges of days.
RangeBucketsHourly(ctx context.Context, arg RangeBucketsHourlyParams) ([]RangeBucketsHourlyRow, error)
RecentResults(ctx context.Context, arg RecentResultsParams) ([]RecentResultsRow, error)
// One monitor's raw results per region.
RegionBuckets(ctx context.Context, arg RegionBucketsParams) ([]RegionBucketsRow, error)
RegionBucketsDaily(ctx context.Context, arg RegionBucketsDailyParams) ([]RegionBucketsDailyRow, error)
@@ -266,7 +282,8 @@ type Querier interface {
// Heartbeats of an organization wait afresh after its suspension, during
// which pings were refused.
RestartHeartbeatWait(ctx context.Context, orgID uuid.UUID) error
// The organization's latest results run by one checker instance.
// The organization's results run by one checker instance, newest first, a
// page from a keyset cursor whose string key is monitor and region.
ResultsByChecker(ctx context.Context, arg ResultsByCheckerParams) ([]ResultsByCheckerRow, error)
ScrubAuditEmail(ctx context.Context, email string) error
SetAgentAllowPrivate(ctx context.Context, arg SetAgentAllowPrivateParams) (int64, error)
+14
View File
@@ -49,3 +49,17 @@ WHERE m.type = 'alertmanager' AND m.enabled AND (sqlc.narg(org_id)::uuid IS NULL
SELECT ok, coalesce(error, '')::text AS error FROM check_results
WHERE org_id = $1 AND monitor_id = $2 AND time > now() - interval '2 days'
ORDER BY time DESC LIMIT 1;
-- name: FiringAlertsPage :many
-- FiringAlerts newest first, a page from a keyset cursor (see paging.go)
-- whose string key is the fingerprint.
SELECT fingerprint, labels, annotations, starts_at, generator_url, updated_at
FROM alertmanager_alerts
WHERE org_id = sqlc.arg(org_id) AND status = 'firing' AND updated_at > sqlc.arg(since)
AND (sqlc.narg(after_t)::timestamptz IS NULL OR (starts_at, fingerprint) < (sqlc.narg(after_t), sqlc.narg(after_s)::text))
AND (sqlc.narg(before_t)::timestamptz IS NULL OR (starts_at, fingerprint) > (sqlc.narg(before_t), sqlc.narg(before_s)::text))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN starts_at END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN fingerprint END DESC,
starts_at, fingerprint
LIMIT sqlc.arg(max_rows);
+8 -4
View File
@@ -3,8 +3,8 @@ INSERT INTO audit_events (kind, org_id, actor_user_id, actor_token_id, action, t
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);
-- name: ListAuditEvents :many
-- Newest first, paged by time. kind narrows to one kind; the row policy
-- already limits what the scope can see.
-- Newest first, a page from a keyset cursor (see paging.go). kind narrows
-- to one kind; the row policy already limits what the scope can see.
SELECT e.id, e.time, e.kind, e.org_id, e.actor_user_id, e.actor_token_id, e.action, e.target_id,
e.details, e.status, coalesce(host(e.ip), '')::text AS ip, coalesce(e.user_agent, '') AS user_agent,
coalesce(e.request_id, '') AS request_id,
@@ -14,8 +14,12 @@ LEFT JOIN users u ON u.id = e.actor_user_id
WHERE e.kind = sqlc.arg(kind)
AND (sqlc.narg(org_id)::uuid IS NULL OR e.org_id = sqlc.narg(org_id))
AND (sqlc.narg(actor)::uuid IS NULL OR e.actor_user_id = sqlc.narg(actor))
AND (sqlc.narg(before)::timestamptz IS NULL OR e.time < sqlc.narg(before))
ORDER BY e.time DESC
AND (sqlc.narg(after_t)::timestamptz IS NULL OR (e.time, e.id) < (sqlc.narg(after_t), sqlc.narg(after_id)::uuid))
AND (sqlc.narg(before_t)::timestamptz IS NULL OR (e.time, e.id) > (sqlc.narg(before_t), sqlc.narg(before_id)::uuid))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN e.time END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN e.id END DESC,
e.time, e.id
LIMIT sqlc.arg(max_rows);
-- name: PurgeAuditEvents :execrows
+27 -9
View File
@@ -12,12 +12,22 @@ FROM check_results
WHERE org_id = $1 AND time > now() - interval '1 day'
ORDER BY monitor_id, region, time DESC;
-- name: RecentResults :many
SELECT time, region, ok, latency_ms, status_code, error, checker_id
-- name: ListResults :many
-- A monitor's results newest first, a page from a keyset cursor (see
-- paging.go) whose string key is region and checker.
SELECT time, region, ok, latency_ms, status_code, error, checker_id,
(region || '|' || checker_id::text)::text AS position
FROM check_results
WHERE org_id = $1 AND monitor_id = $2 AND time > $3
ORDER BY time DESC
LIMIT 500;
WHERE org_id = sqlc.arg(org_id) AND monitor_id = sqlc.arg(monitor_id)
AND (sqlc.narg(after_t)::timestamptz IS NULL
OR time <= sqlc.narg(after_t) AND (time, region || '|' || checker_id::text) < (sqlc.narg(after_t), sqlc.narg(after_s)::text))
AND (sqlc.narg(before_t)::timestamptz IS NULL
OR time >= sqlc.narg(before_t) AND (time, region || '|' || checker_id::text) > (sqlc.narg(before_t), sqlc.narg(before_s)::text))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN time END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN region || '|' || checker_id::text END DESC,
time, region || '|' || checker_id::text
LIMIT sqlc.arg(max_rows);
-- name: UptimeSince :many
-- Uptime per monitor from the hourly aggregate, including the not yet
@@ -130,12 +140,20 @@ WHERE org_id = $1 AND time >= $2
GROUP BY 1, 2;
-- name: ResultsByChecker :many
-- The organization's latest results run by one checker instance.
-- The organization's results run by one checker instance, newest first, a
-- page from a keyset cursor whose string key is monitor and region.
SELECT r.time, r.monitor_id, r.region, r.ok, r.latency_ms, r.status_code, r.error
FROM check_results r
WHERE r.org_id = $1 AND r.checker_id = sqlc.arg(checker_id) AND r.time > now() - interval '1 day'
ORDER BY r.time DESC
LIMIT 50;
WHERE r.org_id = sqlc.arg(org_id) AND r.checker_id = sqlc.arg(checker_id)
AND (sqlc.narg(after_t)::timestamptz IS NULL
OR r.time <= sqlc.narg(after_t) AND (r.time, r.monitor_id::text || '|' || r.region) < (sqlc.narg(after_t), sqlc.narg(after_s)::text))
AND (sqlc.narg(before_t)::timestamptz IS NULL
OR r.time >= sqlc.narg(before_t) AND (r.time, r.monitor_id::text || '|' || r.region) > (sqlc.narg(before_t), sqlc.narg(before_s)::text))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN r.time END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN r.monitor_id::text || '|' || r.region END DESC,
r.time, r.monitor_id::text || '|' || r.region
LIMIT sqlc.arg(max_rows);
-- name: CheckerStats :one
-- How much one instance checked for the organization in the last hour.
+14 -2
View File
@@ -12,9 +12,21 @@ WHERE monitor_id = $1 AND region = $2 AND NOT ok
ORDER BY time DESC LIMIT 1;
-- name: ListEvidence :many
-- Newest first, a page from a keyset cursor (see paging.go).
SELECT id, region, checker_id, time, ok, status_code, error FROM check_evidence
WHERE monitor_id = $1
ORDER BY time DESC LIMIT 100;
WHERE monitor_id = sqlc.arg(monitor_id)
AND (sqlc.narg(after_t)::timestamptz IS NULL OR (time, id) < (sqlc.narg(after_t), sqlc.narg(after_id)::uuid))
AND (sqlc.narg(before_t)::timestamptz IS NULL OR (time, id) > (sqlc.narg(before_t), sqlc.narg(before_id)::uuid))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN time END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN id END DESC,
time, id
LIMIT sqlc.arg(max_rows);
-- name: EvidenceBetween :many
-- Evidence of a monitor in a time span, to link results to it.
SELECT id, region, time FROM check_evidence
WHERE monitor_id = $1 AND time BETWEEN sqlc.arg(since) AND sqlc.arg(until);
-- name: GetEvidence :one
SELECT * FROM check_evidence WHERE id = $1 AND monitor_id = $2;
+10 -5
View File
@@ -10,11 +10,19 @@ WHERE monitor_id = sqlc.arg(monitor_id) AND resolved_at IS NULL
RETURNING *;
-- name: ListIncidents :many
-- Newest first, a page from a keyset cursor (see paging.go); optionally of
-- one monitor.
SELECT i.*, m.name AS monitor_name
FROM incidents i
JOIN monitors m ON m.id = i.monitor_id
ORDER BY i.started_at DESC
LIMIT 200;
WHERE (sqlc.narg(monitor_id)::uuid IS NULL OR i.monitor_id = sqlc.narg(monitor_id))
AND (sqlc.narg(after_t)::timestamptz IS NULL OR (i.started_at, i.id) < (sqlc.narg(after_t), sqlc.narg(after_id)::uuid))
AND (sqlc.narg(before_t)::timestamptz IS NULL OR (i.started_at, i.id) > (sqlc.narg(before_t), sqlc.narg(before_id)::uuid))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN i.started_at END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN i.id END DESC,
i.started_at, i.id
LIMIT sqlc.arg(max_rows);
-- name: EnqueueNotification :exec
INSERT INTO notifications (org_id, channel_id, incident_id, event)
@@ -78,9 +86,6 @@ DELETE FROM notification_channels WHERE id = $1;
-- name: OpenIncidents :many
SELECT * FROM incidents WHERE resolved_at IS NULL;
-- name: MonitorIncidents :many
SELECT * FROM incidents WHERE monitor_id = $1 ORDER BY started_at DESC LIMIT 20;
-- name: IncidentsForMonitors :many
SELECT * FROM incidents
WHERE monitor_id = ANY (sqlc.arg(ids)::uuid[]) AND (resolved_at IS NULL OR resolved_at > sqlc.arg(since))
+10 -4
View File
@@ -21,7 +21,8 @@ RETURNING id, email;
-- name: AdminListOrgs :many
-- System scope: organizations with their usage, limit overrides and owner,
-- newest first, matching search in name, slug or owner email.
-- matching search in name, slug or owner email; newest first, a page from a
-- keyset cursor.
SELECT o.id, o.slug, o.name, o.created_at, o.suspended_at, o.suspended_reason,
o.limit_monitors, o.limit_status_pages, o.limit_regions_per_monitor, o.limit_own_regions_count,
(SELECT count(*) FROM monitors m WHERE m.org_id = o.id)::integer AS monitors,
@@ -38,8 +39,13 @@ LEFT JOIN LATERAL (
FROM memberships m JOIN users u ON u.id = m.user_id
WHERE m.org_id = o.id AND m.is_owner ORDER BY m.created_at LIMIT 1
) ow ON true
WHERE sqlc.arg(search)::text = ''
WHERE (sqlc.arg(search)::text = ''
OR o.name ILIKE '%' || sqlc.arg(search) || '%' OR o.slug::text ILIKE '%' || sqlc.arg(search) || '%'
OR coalesce(ow.email::text, '') ILIKE '%' || sqlc.arg(search) || '%'
ORDER BY o.created_at DESC
OR coalesce(ow.email::text, '') ILIKE '%' || sqlc.arg(search) || '%')
AND (sqlc.narg(after_t)::timestamptz IS NULL OR (o.created_at, o.id) < (sqlc.narg(after_t), sqlc.narg(after_id)::uuid))
AND (sqlc.narg(before_t)::timestamptz IS NULL OR (o.created_at, o.id) > (sqlc.narg(before_t), sqlc.narg(before_id)::uuid))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN o.created_at END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN o.id END DESC,
o.created_at, o.id
LIMIT sqlc.arg(max_rows);
+12
View File
@@ -47,3 +47,15 @@ covered AS (
SELECT c.monitor_id, w.id, w.title, w.description, w.starts_at, w.duration_seconds, w.time_zone,
w.recurrence, w.every, w.weekdays, w.until
FROM covered c JOIN maintenance_windows w ON w.id = c.window_id;
-- name: ListMaintenancePage :many
-- Latest start first, a page from a keyset cursor (see paging.go).
SELECT * FROM maintenance_windows
WHERE true
AND (sqlc.narg(after_t)::timestamptz IS NULL OR (starts_at, id) < (sqlc.narg(after_t), sqlc.narg(after_id)::uuid))
AND (sqlc.narg(before_t)::timestamptz IS NULL OR (starts_at, id) > (sqlc.narg(before_t), sqlc.narg(before_id)::uuid))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN starts_at END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN id END DESC,
starts_at, id
LIMIT sqlc.arg(max_rows);
+13
View File
@@ -20,3 +20,16 @@ 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);
+8 -3
View File
@@ -1,7 +1,7 @@
-- name: AdminListStatusPages :many
-- System scope: public status pages and suspended ones, with their
-- organization and its owner, newest first, matching search in title,
-- slug, domain, organization or owner email.
-- organization and its owner, matching search in title, slug, domain,
-- organization or owner email; newest first, a page from a keyset cursor.
SELECT p.id, p.slug, p.title, p.published, p.custom_domain, p.domain_verified_at,
p.suspended_at, p.suspended_reason, p.created_at,
o.id AS org_id, o.slug AS org_slug, o.name AS org_name, o.suspended_at AS org_suspended_at, o.suspended_reason AS org_suspended_reason,
@@ -20,7 +20,12 @@ WHERE (p.published OR p.suspended_at IS NOT NULL OR o.suspended_at IS NOT NULL)
OR coalesce(p.custom_domain::text, '') ILIKE '%' || sqlc.arg(search) || '%'
OR o.name ILIKE '%' || sqlc.arg(search) || '%' OR o.slug::text ILIKE '%' || sqlc.arg(search) || '%'
OR coalesce(ow.email::text, '') ILIKE '%' || sqlc.arg(search) || '%')
ORDER BY p.created_at DESC
AND (sqlc.narg(after_t)::timestamptz IS NULL OR (p.created_at, p.id) < (sqlc.narg(after_t), sqlc.narg(after_id)::uuid))
AND (sqlc.narg(before_t)::timestamptz IS NULL OR (p.created_at, p.id) > (sqlc.narg(before_t), sqlc.narg(before_id)::uuid))
ORDER BY
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN p.created_at END DESC,
CASE WHEN sqlc.narg(before_t)::timestamptz IS NULL THEN p.id END DESC,
p.created_at, p.id
LIMIT sqlc.arg(max_rows);
-- name: SuspendStatusPage :one
+12
View File
@@ -60,3 +60,15 @@ JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = sqlc.arg(region_
JOIN orgs o ON o.id = m.org_id AND o.suspended_at IS NULL
WHERE m.id = ANY (sqlc.arg(ids)::uuid[]) AND m.enabled
AND (sqlc.narg(agent_org)::uuid IS NULL OR m.org_id = sqlc.narg(agent_org));
-- name: ListMonitorsPage :many
-- By name, a page from a keyset cursor (see paging.go).
SELECT * FROM monitors
WHERE true
AND (sqlc.narg(after_s)::text IS NULL OR (name, id) > (sqlc.narg(after_s), sqlc.narg(after_id)::uuid))
AND (sqlc.narg(before_s)::text IS NULL OR (name, id) < (sqlc.narg(before_s), sqlc.narg(before_id)::uuid))
ORDER BY
CASE WHEN sqlc.narg(before_s)::text IS NULL THEN name END,
CASE WHEN sqlc.narg(before_s)::text IS NULL THEN id END,
name DESC, id DESC
LIMIT sqlc.arg(max_rows);
+2 -1
View File
@@ -23,7 +23,8 @@ func TestResultQueriesFilterByOrg(t *testing.T) {
if strings.Contains(b, ":copyfrom") {
continue
}
if !regexp.MustCompile(`(?i)WHERE[^;]*\borg_id\s*=\s*\$1`).MatchString(b) {
// The organization is the first parameter, positional or named.
if !regexp.MustCompile(`(?i)WHERE[^;]*\borg_id\s*=\s*(\$1|sqlc\.arg\(org_id\))`).MatchString(b) {
t.Errorf("query %s does not filter by org_id = $1", name)
}
}