core/observability-core/internal/db/query.sql.go
Tiago Yamamoto a52bd4519d refactor: optimize Dockerfiles and documentation for core services
- Use Google Distroless images for all services (Go & Node.js).
- Standardize documentation with [PROJECT-NAME].md.
- Add .dockerignore and .gitignore to all projects.
- Remove docker-compose.yml in favor of docker run instructions.
- Fix Go version and dependency issues in observability, repo-integrations, and security-governance.
- Add Podman support (fully qualified image names).
- Update Dashboard to use Node.js static server for Distroless compatibility.
2025-12-30 13:22:34 -03:00

360 lines
8.1 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: query.sql
package db
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const createAlertRule = `-- name: CreateAlertRule :one
INSERT INTO alert_rules (check_id, name, threshold, operator, for_duration, severity)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id, check_id, name, threshold, operator, for_duration, severity, created_at, updated_at
`
type CreateAlertRuleParams struct {
CheckID pgtype.UUID `json:"check_id"`
Name string `json:"name"`
Threshold float64 `json:"threshold"`
Operator string `json:"operator"`
ForDuration int64 `json:"for_duration"`
Severity AlertSeverity `json:"severity"`
}
func (q *Queries) CreateAlertRule(ctx context.Context, arg CreateAlertRuleParams) (AlertRule, error) {
row := q.db.QueryRow(ctx, createAlertRule,
arg.CheckID,
arg.Name,
arg.Threshold,
arg.Operator,
arg.ForDuration,
arg.Severity,
)
var i AlertRule
err := row.Scan(
&i.ID,
&i.CheckID,
&i.Name,
&i.Threshold,
&i.Operator,
&i.ForDuration,
&i.Severity,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const createCheck = `-- name: CreateCheck :one
INSERT INTO checks (target_id, type, interval_seconds, timeout_seconds)
VALUES ($1, $2, $3, $4)
RETURNING id, target_id, type, interval_seconds, timeout_seconds, is_active, created_at, updated_at
`
type CreateCheckParams struct {
TargetID pgtype.UUID `json:"target_id"`
Type CheckType `json:"type"`
IntervalSeconds int32 `json:"interval_seconds"`
TimeoutSeconds int32 `json:"timeout_seconds"`
}
func (q *Queries) CreateCheck(ctx context.Context, arg CreateCheckParams) (Check, error) {
row := q.db.QueryRow(ctx, createCheck,
arg.TargetID,
arg.Type,
arg.IntervalSeconds,
arg.TimeoutSeconds,
)
var i Check
err := row.Scan(
&i.ID,
&i.TargetID,
&i.Type,
&i.IntervalSeconds,
&i.TimeoutSeconds,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const createIncident = `-- name: CreateIncident :one
INSERT INTO incidents (alert_rule_id, status, start_time)
VALUES ($1, $2, $3)
RETURNING id, alert_rule_id, status, start_time, end_time, created_at, updated_at
`
type CreateIncidentParams struct {
AlertRuleID pgtype.UUID `json:"alert_rule_id"`
Status IncidentStatus `json:"status"`
StartTime pgtype.Timestamptz `json:"start_time"`
}
func (q *Queries) CreateIncident(ctx context.Context, arg CreateIncidentParams) (Incident, error) {
row := q.db.QueryRow(ctx, createIncident, arg.AlertRuleID, arg.Status, arg.StartTime)
var i Incident
err := row.Scan(
&i.ID,
&i.AlertRuleID,
&i.Status,
&i.StartTime,
&i.EndTime,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const createMetric = `-- name: CreateMetric :one
INSERT INTO metrics (time, check_id, value, tags)
VALUES ($1, $2, $3, $4)
RETURNING time, check_id, value, tags
`
type CreateMetricParams struct {
Time pgtype.Timestamptz `json:"time"`
CheckID pgtype.UUID `json:"check_id"`
Value float64 `json:"value"`
Tags []byte `json:"tags"`
}
func (q *Queries) CreateMetric(ctx context.Context, arg CreateMetricParams) (Metric, error) {
row := q.db.QueryRow(ctx, createMetric,
arg.Time,
arg.CheckID,
arg.Value,
arg.Tags,
)
var i Metric
err := row.Scan(
&i.Time,
&i.CheckID,
&i.Value,
&i.Tags,
)
return i, err
}
const createTarget = `-- name: CreateTarget :one
INSERT INTO targets (name, type, config)
VALUES ($1, $2, $3)
RETURNING id, name, type, config, created_at, updated_at
`
type CreateTargetParams struct {
Name string `json:"name"`
Type TargetType `json:"type"`
Config []byte `json:"config"`
}
func (q *Queries) CreateTarget(ctx context.Context, arg CreateTargetParams) (Target, error) {
row := q.db.QueryRow(ctx, createTarget, arg.Name, arg.Type, arg.Config)
var i Target
err := row.Scan(
&i.ID,
&i.Name,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getCheck = `-- name: GetCheck :one
SELECT id, target_id, type, interval_seconds, timeout_seconds, is_active, created_at, updated_at FROM checks
WHERE id = $1
`
func (q *Queries) GetCheck(ctx context.Context, id pgtype.UUID) (Check, error) {
row := q.db.QueryRow(ctx, getCheck, id)
var i Check
err := row.Scan(
&i.ID,
&i.TargetID,
&i.Type,
&i.IntervalSeconds,
&i.TimeoutSeconds,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getIncident = `-- name: GetIncident :one
SELECT id, alert_rule_id, status, start_time, end_time, created_at, updated_at FROM incidents
WHERE id = $1
`
func (q *Queries) GetIncident(ctx context.Context, id pgtype.UUID) (Incident, error) {
row := q.db.QueryRow(ctx, getIncident, id)
var i Incident
err := row.Scan(
&i.ID,
&i.AlertRuleID,
&i.Status,
&i.StartTime,
&i.EndTime,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const getMetricsForCheck = `-- name: GetMetricsForCheck :many
SELECT time, check_id, value, tags FROM metrics
WHERE check_id = $1 AND time >= $2 AND time <= $3
ORDER BY time DESC
`
type GetMetricsForCheckParams struct {
CheckID pgtype.UUID `json:"check_id"`
Time pgtype.Timestamptz `json:"time"`
Time_2 pgtype.Timestamptz `json:"time_2"`
}
func (q *Queries) GetMetricsForCheck(ctx context.Context, arg GetMetricsForCheckParams) ([]Metric, error) {
rows, err := q.db.Query(ctx, getMetricsForCheck, arg.CheckID, arg.Time, arg.Time_2)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Metric
for rows.Next() {
var i Metric
if err := rows.Scan(
&i.Time,
&i.CheckID,
&i.Value,
&i.Tags,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getTarget = `-- name: GetTarget :one
SELECT id, name, type, config, created_at, updated_at FROM targets
WHERE id = $1
`
func (q *Queries) GetTarget(ctx context.Context, id pgtype.UUID) (Target, error) {
row := q.db.QueryRow(ctx, getTarget, id)
var i Target
err := row.Scan(
&i.ID,
&i.Name,
&i.Type,
&i.Config,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listAlertRules = `-- name: ListAlertRules :many
SELECT id, check_id, name, threshold, operator, for_duration, severity, created_at, updated_at FROM alert_rules
`
func (q *Queries) ListAlertRules(ctx context.Context) ([]AlertRule, error) {
rows, err := q.db.Query(ctx, listAlertRules)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AlertRule
for rows.Next() {
var i AlertRule
if err := rows.Scan(
&i.ID,
&i.CheckID,
&i.Name,
&i.Threshold,
&i.Operator,
&i.ForDuration,
&i.Severity,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listChecks = `-- name: ListChecks :many
SELECT id, target_id, type, interval_seconds, timeout_seconds, is_active, created_at, updated_at FROM checks
WHERE is_active = TRUE
`
func (q *Queries) ListChecks(ctx context.Context) ([]Check, error) {
rows, err := q.db.Query(ctx, listChecks)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Check
for rows.Next() {
var i Check
if err := rows.Scan(
&i.ID,
&i.TargetID,
&i.Type,
&i.IntervalSeconds,
&i.TimeoutSeconds,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateIncidentStatus = `-- name: UpdateIncidentStatus :one
UPDATE incidents
SET status = $2, updated_at = NOW()
WHERE id = $1
RETURNING id, alert_rule_id, status, start_time, end_time, created_at, updated_at
`
type UpdateIncidentStatusParams struct {
ID pgtype.UUID `json:"id"`
Status IncidentStatus `json:"status"`
}
func (q *Queries) UpdateIncidentStatus(ctx context.Context, arg UpdateIncidentStatusParams) (Incident, error) {
row := q.db.QueryRow(ctx, updateIncidentStatus, arg.ID, arg.Status)
var i Incident
err := row.Scan(
&i.ID,
&i.AlertRuleID,
&i.Status,
&i.StartTime,
&i.EndTime,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}