creatorupdatordeprecate

This commit is contained in:
Michael McGuinness
2025-01-03 13:41:07 +00:00
parent 0ac156f0e1
commit 788b21594c
36 changed files with 545 additions and 226 deletions
+10 -7
View File
@@ -35,15 +35,18 @@ func (q *Queries) GetCollectorFromJobID(ctx context.Context, jobid pgtype.UUID)
}
const getCollectorQueries = `-- name: GetCollectorQueries :many
SELECT collectorId, queryId, type, requiredQueryId, queryVersion FROM collectorQueryDependencyTree WHERE collectorId = $1
SELECT collectorId, queryId, type, queryVersion, ARRAY_AGG(requiredQueryId) AS requiredIds
FROM collectorQueryDependencyTree
WHERE collectorId = $1
GROUP BY queryId, collectorId, type, queryVersion
`
type GetCollectorQueriesRow struct {
Collectorid pgtype.UUID
Queryid pgtype.UUID
Type NullQuerytype
Requiredqueryid pgtype.UUID
Queryversion pgtype.Int4
Collectorid pgtype.UUID
Queryid pgtype.UUID
Type NullQuerytype
Queryversion pgtype.Int4
Requiredids []pgtype.UUID
}
func (q *Queries) GetCollectorQueries(ctx context.Context, collectorid pgtype.UUID) ([]GetCollectorQueriesRow, error) {
@@ -59,8 +62,8 @@ func (q *Queries) GetCollectorQueries(ctx context.Context, collectorid pgtype.UU
&i.Collectorid,
&i.Queryid,
&i.Type,
&i.Requiredqueryid,
&i.Queryversion,
&i.Requiredids,
); err != nil {
return nil, err
}
+7
View File
@@ -107,6 +107,13 @@ type Queryconfig struct {
Removedversion pgtype.Int4
}
type Querydeprecation struct {
ID pgtype.UUID
Queryid pgtype.UUID
Time pgtype.Timestamp
Removedat pgtype.Timestamp
}
type Requiredquery struct {
ID pgtype.UUID
Queryid pgtype.UUID
+33
View File
@@ -11,6 +11,15 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
const deprecateQuery = `-- name: DeprecateQuery :exec
INSERT INTO queryDeprecations (queryId) VALUES ($1) RETURNING id
`
func (q *Queries) DeprecateQuery(ctx context.Context, queryid pgtype.UUID) error {
_, err := q.db.Exec(ctx, deprecateQuery, queryid)
return err
}
const getQuery = `-- name: GetQuery :one
SELECT q.id, q.type, q.activeVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
FROM queries AS q
@@ -65,3 +74,27 @@ func (q *Queries) GetQueryConfig(ctx context.Context, arg GetQueryConfigParams)
err := row.Scan(&i.ID, &i.Config)
return i, err
}
const getQueryType = `-- name: GetQueryType :one
SELECT type FROM queries where id = $1
`
func (q *Queries) GetQueryType(ctx context.Context, id pgtype.UUID) (Querytype, error) {
row := q.db.QueryRow(ctx, getQueryType, id)
var type_ Querytype
err := row.Scan(&type_)
return type_, err
}
const isQueryDeprecated = `-- name: IsQueryDeprecated :one
SELECT EXISTS (
SELECT 1 FROM queryDeprecations where queryId = $1 and removedAt is not null
)
`
func (q *Queries) IsQueryDeprecated(ctx context.Context, queryid pgtype.UUID) (bool, error) {
row := q.db.QueryRow(ctx, isQueryDeprecated, queryid)
var exists bool
err := row.Scan(&exists)
return exists, err
}