feat(store): add nested monitor groups
A trigger rejects cycles and nesting deeper than eight levels; composite foreign keys keep groups and their monitors in one organization. Refs #57 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
6e2f8d0626
commit
2d7f326d38
7 files changed
+306
-11
No files matched your search
@@ -56,9 +56,9 @@ func (q *Queries) AllMonitorRegions(ctx context.Context) ([]AllMonitorRegionsRow
|
||||
}
|
||||
|
||||
const createMonitor = `-- name: CreateMonitor :one
|
||||
INSERT INTO monitors (org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, confirmations)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations
|
||||
INSERT INTO monitors (org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, confirmations, group_id)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id
|
||||
`
|
||||
|
||||
type CreateMonitorParams struct {
|
||||
@@ -71,6 +71,7 @@ type CreateMonitorParams struct {
|
||||
Config []byte
|
||||
Enabled bool
|
||||
Confirmations int32
|
||||
GroupID *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CreateMonitor(ctx context.Context, arg CreateMonitorParams) (Monitor, error) {
|
||||
@@ -84,6 +85,7 @@ func (q *Queries) CreateMonitor(ctx context.Context, arg CreateMonitorParams) (M
|
||||
arg.Config,
|
||||
arg.Enabled,
|
||||
arg.Confirmations,
|
||||
arg.GroupID,
|
||||
)
|
||||
var i Monitor
|
||||
err := row.Scan(
|
||||
@@ -99,6 +101,7 @@ func (q *Queries) CreateMonitor(ctx context.Context, arg CreateMonitorParams) (M
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -125,7 +128,7 @@ func (q *Queries) DeleteMonitorRegions(ctx context.Context, monitorID uuid.UUID)
|
||||
}
|
||||
|
||||
const getMonitor = `-- name: GetMonitor :one
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations FROM monitors WHERE id = $1
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error) {
|
||||
@@ -144,6 +147,7 @@ func (q *Queries) GetMonitor(ctx context.Context, id uuid.UUID) (Monitor, error)
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -185,7 +189,7 @@ func (q *Queries) ListEnabledMonitorsForSchedule(ctx context.Context) ([]ListEna
|
||||
}
|
||||
|
||||
const listMonitors = `-- name: ListMonitors :many
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations FROM monitors ORDER BY name
|
||||
SELECT id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id FROM monitors ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
||||
@@ -210,6 +214,7 @@ func (q *Queries) ListMonitors(ctx context.Context) ([]Monitor, error) {
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -246,7 +251,7 @@ func (q *Queries) MonitorRegions(ctx context.Context, monitorID uuid.UUID) ([]uu
|
||||
}
|
||||
|
||||
const monitorsForJobs = `-- name: MonitorsForJobs :many
|
||||
SELECT m.id, m.org_id, m.name, m.type, m.target, m.interval_seconds, m.timeout_ms, m.config, m.enabled, m.created_at, m.updated_at, m.confirmations FROM monitors m
|
||||
SELECT m.id, m.org_id, m.name, m.type, m.target, m.interval_seconds, m.timeout_ms, m.config, m.enabled, m.created_at, m.updated_at, m.confirmations, m.group_id FROM monitors m
|
||||
JOIN monitor_regions r ON r.monitor_id = m.id AND r.region_id = $1
|
||||
WHERE m.id = ANY ($2::uuid[]) AND m.enabled
|
||||
AND ($3::uuid IS NULL OR m.org_id = $3)
|
||||
@@ -283,6 +288,7 @@ func (q *Queries) MonitorsForJobs(ctx context.Context, arg MonitorsForJobsParams
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -351,9 +357,9 @@ func (q *Queries) MonitorsForResults(ctx context.Context, arg MonitorsForResults
|
||||
|
||||
const updateMonitor = `-- name: UpdateMonitor :one
|
||||
UPDATE monitors SET name = $2, type = $3, target = $4, interval_seconds = $5,
|
||||
timeout_ms = $6, config = $7, enabled = $8, confirmations = $9, updated_at = now()
|
||||
timeout_ms = $6, config = $7, enabled = $8, confirmations = $9, group_id = $10, updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations
|
||||
RETURNING id, org_id, name, type, target, interval_seconds, timeout_ms, config, enabled, created_at, updated_at, confirmations, group_id
|
||||
`
|
||||
|
||||
type UpdateMonitorParams struct {
|
||||
@@ -366,6 +372,7 @@ type UpdateMonitorParams struct {
|
||||
Config []byte
|
||||
Enabled bool
|
||||
Confirmations int32
|
||||
GroupID *uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateMonitor(ctx context.Context, arg UpdateMonitorParams) (Monitor, error) {
|
||||
@@ -379,6 +386,7 @@ func (q *Queries) UpdateMonitor(ctx context.Context, arg UpdateMonitorParams) (M
|
||||
arg.Config,
|
||||
arg.Enabled,
|
||||
arg.Confirmations,
|
||||
arg.GroupID,
|
||||
)
|
||||
var i Monitor
|
||||
err := row.Scan(
|
||||
@@ -394,6 +402,7 @@ func (q *Queries) UpdateMonitor(ctx context.Context, arg UpdateMonitorParams) (M
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Confirmations,
|
||||
&i.GroupID,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in new issue
Block a user