feat(store): add monitors, regions, agents and check result hypertable
check_results has no row-level security because TimescaleDB refuses compression and continuous aggregates on such tables. Every results query takes org_id as a parameter, which a test enforces. Refs #10, #13 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
55559c8b0a
commit
00658d49a2
12 files changed
+1093
No files matched your search
@@ -9,6 +9,48 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// iteratorForInsertCheckResults implements pgx.CopyFromSource.
|
||||
type iteratorForInsertCheckResults struct {
|
||||
rows []InsertCheckResultsParams
|
||||
skippedFirstNextCall bool
|
||||
}
|
||||
|
||||
func (r *iteratorForInsertCheckResults) Next() bool {
|
||||
if len(r.rows) == 0 {
|
||||
return false
|
||||
}
|
||||
if !r.skippedFirstNextCall {
|
||||
r.skippedFirstNextCall = true
|
||||
return true
|
||||
}
|
||||
r.rows = r.rows[1:]
|
||||
return len(r.rows) > 0
|
||||
}
|
||||
|
||||
func (r iteratorForInsertCheckResults) Values() ([]interface{}, error) {
|
||||
return []interface{}{
|
||||
r.rows[0].Time,
|
||||
r.rows[0].OrgID,
|
||||
r.rows[0].MonitorID,
|
||||
r.rows[0].Region,
|
||||
r.rows[0].CheckerID,
|
||||
r.rows[0].Ok,
|
||||
r.rows[0].LatencyMs,
|
||||
r.rows[0].StatusCode,
|
||||
r.rows[0].Error,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r iteratorForInsertCheckResults) Err() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// check_results and its aggregates have no row-level security (see
|
||||
// migration 00013). Every query here must filter by org_id.
|
||||
func (q *Queries) InsertCheckResults(ctx context.Context, arg []InsertCheckResultsParams) (int64, error) {
|
||||
return q.db.CopyFrom(ctx, []string{"check_results"}, []string{"time", "org_id", "monitor_id", "region", "checker_id", "ok", "latency_ms", "status_code", "error"}, &iteratorForInsertCheckResults{rows: arg})
|
||||
}
|
||||
|
||||
// iteratorForInsertRecoveryCodes implements pgx.CopyFromSource.
|
||||
type iteratorForInsertRecoveryCodes struct {
|
||||
rows []InsertRecoveryCodesParams
|
||||
|
||||
Reference in new issue
Block a user