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
@@ -0,0 +1,30 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestResultQueriesFilterByOrg guards the tables that cannot use row-level
|
||||
// security: every read of check results must be restricted to one org.
|
||||
func TestResultQueriesFilterByOrg(t *testing.T) {
|
||||
src, err := os.ReadFile("queries/check_results.sql")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
blocks := regexp.MustCompile(`(?m)^-- name: `).Split(string(src), -1)[1:]
|
||||
if len(blocks) == 0 {
|
||||
t.Fatal("no queries found")
|
||||
}
|
||||
for _, b := range blocks {
|
||||
name, _, _ := strings.Cut(b, " ")
|
||||
if strings.Contains(b, ":copyfrom") {
|
||||
continue
|
||||
}
|
||||
if !regexp.MustCompile(`(?i)WHERE[^;]*\borg_id\s*=\s*\$1`).MatchString(b) {
|
||||
t.Errorf("query %s does not filter by org_id = $1", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user