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
380 lines
9.2 KiB
Go
380 lines
9.2 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: maintenance.sql
|
|
|
|
package store
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const addMaintenanceTarget = `-- name: AddMaintenanceTarget :exec
|
|
INSERT INTO maintenance_targets (window_id, org_id, monitor_id, group_id) VALUES ($1, $2, $3, $4)
|
|
`
|
|
|
|
type AddMaintenanceTargetParams struct {
|
|
WindowID uuid.UUID
|
|
OrgID uuid.UUID
|
|
MonitorID *uuid.UUID
|
|
GroupID *uuid.UUID
|
|
}
|
|
|
|
func (q *Queries) AddMaintenanceTarget(ctx context.Context, arg AddMaintenanceTargetParams) error {
|
|
_, err := q.db.Exec(ctx, addMaintenanceTarget,
|
|
arg.WindowID,
|
|
arg.OrgID,
|
|
arg.MonitorID,
|
|
arg.GroupID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const clearMaintenanceTargets = `-- name: ClearMaintenanceTargets :exec
|
|
DELETE FROM maintenance_targets WHERE window_id = $1
|
|
`
|
|
|
|
func (q *Queries) ClearMaintenanceTargets(ctx context.Context, windowID uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, clearMaintenanceTargets, windowID)
|
|
return err
|
|
}
|
|
|
|
const createMaintenance = `-- name: CreateMaintenance :one
|
|
INSERT INTO maintenance_windows (org_id, title, description, starts_at, duration_seconds, time_zone, recurrence, every, weekdays, until)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
RETURNING id, org_id, title, description, starts_at, duration_seconds, time_zone, recurrence, every, weekdays, until, created_at, updated_at
|
|
`
|
|
|
|
type CreateMaintenanceParams struct {
|
|
OrgID uuid.UUID
|
|
Title string
|
|
Description string
|
|
StartsAt time.Time
|
|
DurationSeconds int32
|
|
TimeZone string
|
|
Recurrence string
|
|
Every int32
|
|
Weekdays []int16
|
|
Until *time.Time
|
|
}
|
|
|
|
func (q *Queries) CreateMaintenance(ctx context.Context, arg CreateMaintenanceParams) (MaintenanceWindow, error) {
|
|
row := q.db.QueryRow(ctx, createMaintenance,
|
|
arg.OrgID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.StartsAt,
|
|
arg.DurationSeconds,
|
|
arg.TimeZone,
|
|
arg.Recurrence,
|
|
arg.Every,
|
|
arg.Weekdays,
|
|
arg.Until,
|
|
)
|
|
var i MaintenanceWindow
|
|
err := row.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,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteMaintenance = `-- name: DeleteMaintenance :execrows
|
|
DELETE FROM maintenance_windows WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteMaintenance(ctx context.Context, id uuid.UUID) (int64, error) {
|
|
result, err := q.db.Exec(ctx, deleteMaintenance, id)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return result.RowsAffected(), nil
|
|
}
|
|
|
|
const getMaintenance = `-- name: GetMaintenance :one
|
|
SELECT id, org_id, title, description, starts_at, duration_seconds, time_zone, recurrence, every, weekdays, until, created_at, updated_at FROM maintenance_windows WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetMaintenance(ctx context.Context, id uuid.UUID) (MaintenanceWindow, error) {
|
|
row := q.db.QueryRow(ctx, getMaintenance, id)
|
|
var i MaintenanceWindow
|
|
err := row.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,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listMaintenance = `-- name: ListMaintenance :many
|
|
SELECT id, org_id, title, description, starts_at, duration_seconds, time_zone, recurrence, every, weekdays, until, created_at, updated_at FROM maintenance_windows ORDER BY starts_at, title
|
|
`
|
|
|
|
func (q *Queries) ListMaintenance(ctx context.Context) ([]MaintenanceWindow, error) {
|
|
rows, err := q.db.Query(ctx, listMaintenance)
|
|
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 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
|
|
`
|
|
|
|
func (q *Queries) ListMaintenanceTargets(ctx context.Context) ([]MaintenanceTarget, error) {
|
|
rows, err := q.db.Query(ctx, listMaintenanceTargets)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []MaintenanceTarget{}
|
|
for rows.Next() {
|
|
var i MaintenanceTarget
|
|
if err := rows.Scan(
|
|
&i.WindowID,
|
|
&i.OrgID,
|
|
&i.MonitorID,
|
|
&i.GroupID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const maintenanceForMonitors = `-- name: MaintenanceForMonitors :many
|
|
WITH RECURSIVE chain AS (
|
|
SELECT m.id AS monitor_id, m.group_id
|
|
FROM monitors m WHERE m.id = ANY ($1::uuid[]) AND m.group_id IS NOT NULL
|
|
UNION ALL
|
|
SELECT c.monitor_id, g.parent_id
|
|
FROM chain c JOIN monitor_groups g ON g.id = c.group_id
|
|
WHERE g.parent_id IS NOT NULL
|
|
),
|
|
covered AS (
|
|
SELECT t.window_id, t.monitor_id FROM maintenance_targets t WHERE t.monitor_id = ANY ($1::uuid[])
|
|
UNION
|
|
SELECT t.window_id, c.monitor_id FROM maintenance_targets t JOIN chain c ON c.group_id = t.group_id
|
|
)
|
|
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
|
|
`
|
|
|
|
type MaintenanceForMonitorsRow struct {
|
|
MonitorID *uuid.UUID
|
|
ID uuid.UUID
|
|
Title string
|
|
Description string
|
|
StartsAt time.Time
|
|
DurationSeconds int32
|
|
TimeZone string
|
|
Recurrence string
|
|
Every int32
|
|
Weekdays []int16
|
|
Until *time.Time
|
|
}
|
|
|
|
// System scope: windows covering any of the monitors, directly or through
|
|
// their group or one of its ancestors.
|
|
func (q *Queries) MaintenanceForMonitors(ctx context.Context, ids []uuid.UUID) ([]MaintenanceForMonitorsRow, error) {
|
|
rows, err := q.db.Query(ctx, maintenanceForMonitors, ids)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []MaintenanceForMonitorsRow{}
|
|
for rows.Next() {
|
|
var i MaintenanceForMonitorsRow
|
|
if err := rows.Scan(
|
|
&i.MonitorID,
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.StartsAt,
|
|
&i.DurationSeconds,
|
|
&i.TimeZone,
|
|
&i.Recurrence,
|
|
&i.Every,
|
|
&i.Weekdays,
|
|
&i.Until,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateMaintenance = `-- name: UpdateMaintenance :one
|
|
UPDATE maintenance_windows
|
|
SET title = $2, description = $3, starts_at = $4, duration_seconds = $5, time_zone = $6,
|
|
recurrence = $7, every = $8, weekdays = $9, until = $10, updated_at = now()
|
|
WHERE id = $1
|
|
RETURNING id, org_id, title, description, starts_at, duration_seconds, time_zone, recurrence, every, weekdays, until, created_at, updated_at
|
|
`
|
|
|
|
type UpdateMaintenanceParams struct {
|
|
ID uuid.UUID
|
|
Title string
|
|
Description string
|
|
StartsAt time.Time
|
|
DurationSeconds int32
|
|
TimeZone string
|
|
Recurrence string
|
|
Every int32
|
|
Weekdays []int16
|
|
Until *time.Time
|
|
}
|
|
|
|
func (q *Queries) UpdateMaintenance(ctx context.Context, arg UpdateMaintenanceParams) (MaintenanceWindow, error) {
|
|
row := q.db.QueryRow(ctx, updateMaintenance,
|
|
arg.ID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.StartsAt,
|
|
arg.DurationSeconds,
|
|
arg.TimeZone,
|
|
arg.Recurrence,
|
|
arg.Every,
|
|
arg.Weekdays,
|
|
arg.Until,
|
|
)
|
|
var i MaintenanceWindow
|
|
err := row.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,
|
|
)
|
|
return i, err
|
|
}
|