feat(store): add incidents, notification channels and delivery outbox
At most one open incident per monitor is enforced by a partial unique index. Refs #15, #16 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
4b4e134bfd
commit
ffef63e586
9 files changed
+770
-11
No files matched your search
@@ -70,6 +70,44 @@ func (q *Queries) LatestResults(ctx context.Context, orgID uuid.UUID) ([]LatestR
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const latestResultsForMonitor = `-- name: LatestResultsForMonitor :many
|
||||
SELECT DISTINCT ON (region) region, ok, error
|
||||
FROM check_results
|
||||
WHERE org_id = $1 AND monitor_id = $2 AND time > now() - interval '1 day'
|
||||
ORDER BY region, time DESC
|
||||
`
|
||||
|
||||
type LatestResultsForMonitorParams struct {
|
||||
OrgID uuid.UUID
|
||||
MonitorID uuid.UUID
|
||||
}
|
||||
|
||||
type LatestResultsForMonitorRow struct {
|
||||
Region string
|
||||
Ok bool
|
||||
Error *string
|
||||
}
|
||||
|
||||
func (q *Queries) LatestResultsForMonitor(ctx context.Context, arg LatestResultsForMonitorParams) ([]LatestResultsForMonitorRow, error) {
|
||||
rows, err := q.db.Query(ctx, latestResultsForMonitor, arg.OrgID, arg.MonitorID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []LatestResultsForMonitorRow{}
|
||||
for rows.Next() {
|
||||
var i LatestResultsForMonitorRow
|
||||
if err := rows.Scan(&i.Region, &i.Ok, &i.Error); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const recentResults = `-- name: RecentResults :many
|
||||
SELECT time, region, ok, latency_ms, status_code, error
|
||||
FROM check_results
|
||||
|
||||
Reference in new issue
Block a user