feat(store): store maintenance windows for monitors and groups
Groups cover their subgroups; a recursive query resolves which windows apply to a monitor. Status page descriptions may be longer now that they are Markdown. Refs #71 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
c5f7005829
commit
259b3b8e05
6 files changed
+458
No files matched your search
@@ -0,0 +1,49 @@
|
||||
-- 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 *;
|
||||
|
||||
-- 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 *;
|
||||
|
||||
-- name: DeleteMaintenance :execrows
|
||||
DELETE FROM maintenance_windows WHERE id = $1;
|
||||
|
||||
-- name: GetMaintenance :one
|
||||
SELECT * FROM maintenance_windows WHERE id = $1;
|
||||
|
||||
-- name: ListMaintenance :many
|
||||
SELECT * FROM maintenance_windows ORDER BY starts_at, title;
|
||||
|
||||
-- name: ClearMaintenanceTargets :exec
|
||||
DELETE FROM maintenance_targets WHERE window_id = $1;
|
||||
|
||||
-- name: AddMaintenanceTarget :exec
|
||||
INSERT INTO maintenance_targets (window_id, org_id, monitor_id, group_id) VALUES ($1, $2, $3, $4);
|
||||
|
||||
-- name: ListMaintenanceTargets :many
|
||||
SELECT * FROM maintenance_targets;
|
||||
|
||||
-- name: MaintenanceForMonitors :many
|
||||
-- System scope: windows covering any of the monitors, directly or through
|
||||
-- their group or one of its ancestors.
|
||||
WITH RECURSIVE chain AS (
|
||||
SELECT m.id AS monitor_id, m.group_id
|
||||
FROM monitors m WHERE m.id = ANY (sqlc.arg(ids)::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 (sqlc.arg(ids)::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;
|
||||
Reference in new issue
Block a user