-- name: ListCollectorQueries :many
SELECT * FROM collectorQueryDependencyTree WHERE jobId = @jobId;

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

-- name: GetCollector :one
SELECT * FROM fullActiveCollectors WHERE jobId = @jobId LIMIT 1;

-- name: AddLatestCollectorVersion :one
INSERT INTO collectorVersions (jobId) VALUES ($1) RETURNING id;

-- name: SetActiveCollectorVersion :exec
INSERT INTO collectorActiveVersions (jobId, versionId) VALUES ($1, $2);

-- name: SetCollectorCleanVersion :exec
INSERT INTO collectorMinCleanVersions (jobId, addedVersion, versionId) VALUES ($1, $2, $3);

-- name: SetCollectorTextVersion :exec
INSERT INTO collectorMinTextVersions (jobId, addedVersion, versionId) VALUES ($1, $2, $3);

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

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