feat(store): add status pages and their components
Composite foreign keys keep pages from listing monitors of other organizations, independent of row-level security. Refs #21 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
b831478143
commit
d820547e8c
9 files changed
+570
No files matched your search
@@ -52,6 +52,52 @@ func (q *Queries) DailyBuckets(ctx context.Context, arg DailyBucketsParams) ([]D
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const dailyBucketsForMonitors = `-- name: DailyBucketsForMonitors :many
|
||||
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count
|
||||
FROM check_results_1d
|
||||
WHERE org_id = $1 AND monitor_id = ANY ($3::uuid[]) AND bucket >= $2
|
||||
GROUP BY monitor_id, bucket
|
||||
ORDER BY monitor_id, bucket
|
||||
`
|
||||
|
||||
type DailyBucketsForMonitorsParams struct {
|
||||
OrgID uuid.UUID
|
||||
Bucket interface{}
|
||||
Ids []uuid.UUID
|
||||
}
|
||||
|
||||
type DailyBucketsForMonitorsRow struct {
|
||||
MonitorID uuid.UUID
|
||||
Bucket time.Time
|
||||
Total int64
|
||||
OkCount int64
|
||||
}
|
||||
|
||||
func (q *Queries) DailyBucketsForMonitors(ctx context.Context, arg DailyBucketsForMonitorsParams) ([]DailyBucketsForMonitorsRow, error) {
|
||||
rows, err := q.db.Query(ctx, dailyBucketsForMonitors, arg.OrgID, arg.Bucket, arg.Ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []DailyBucketsForMonitorsRow{}
|
||||
for rows.Next() {
|
||||
var i DailyBucketsForMonitorsRow
|
||||
if err := rows.Scan(
|
||||
&i.MonitorID,
|
||||
&i.Bucket,
|
||||
&i.Total,
|
||||
&i.OkCount,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const hourlyBuckets = `-- name: HourlyBuckets :many
|
||||
SELECT monitor_id, bucket::timestamptz AS bucket, sum(total)::bigint AS total, sum(ok_count)::bigint AS ok_count,
|
||||
(sum(avg_latency_ms * total) / nullif(sum(total), 0))::real AS avg_latency_ms
|
||||
|
||||
Reference in new issue
Block a user