-- name: ListCollectorQueries :many
SELECT * FROM collectorQueryDependencyTree WHERE collectorId = $1;

-- name: GetCollectorByJobID :one
SELECT * FROM fullActiveCollectors WHERE jobId = $1 LIMIT 1;

-- name: GetCollector :one
SELECT * FROM fullActiveCollectors WHERE id = $1 LIMIT 1;

-- name: CreateCollector :one
INSERT INTO collectors (jobId) VALUES ($1) RETURNING id;

-- name: UpdateCollector :exec
UPDATE collectors SET latestVersion = $1, activeVersion = $2 WHERE id = $3;

-- name: AddCollectorCodeVersion :exec
INSERT INTO collectorCodeVersions (collectorId, addedVersion, minCleanVersion, minTextVersion) VALUES ($1, $2, $3, $4);

-- name: RemoveCollectorCodeVersion :exec
UPDATE collectorCodeVersions SET removedVersion = $1 WHERE collectorId = $2 and removedVersion is null;

-- name: AddCollectorQuery :exec
INSERT INTO collectorQueries (collectorId, name, queryId, addedVersion) VALUES ($1, $2, $3, $4);

-- name: RemoveCollectorQuery :exec
UPDATE collectorQueries SET removedVersion = $1 WHERE queryId = $2 and collectorId = $3 and removedVersion is null;
