5b7160fe44
Job Collector * createstructure * mostupdatevalidation * repocollectorupdate * updateoutline * updatevalidation * scriptupdate * cleanupdockerignore * update * collectorupdateapi
33 lines
1.7 KiB
SQL
33 lines
1.7 KiB
SQL
CREATE VIEW fullActiveCollectors AS
|
|
SELECT DISTINCT c.id, c.jobId, cv.minCleanVersion, cv.minTextVersion, c.activeVersion, c.latestVersion,
|
|
jsonb_object_agg(q.name, q.queryId) FILTER (WHERE q.name is not null) AS fields
|
|
FROM collectors AS c
|
|
LEFT JOIN collectorCodeVersions AS cv ON c.id = cv.collectorId
|
|
AND c.activeVersion >= cv.addedVersion
|
|
and c.activeVersion < COALESCE(cv.removedVersion, c.activeVersion + 1)
|
|
LEFT JOIN collectorQueries AS q ON c.id = q.collectorId
|
|
AND c.activeVersion >= q.addedVersion
|
|
and c.activeVersion < COALESCE(q.removedVersion, c.activeVersion + 1)
|
|
GROUP BY c.id, c.jobId, cv.minCleanVersion, cv.minTextVersion;
|
|
|
|
CREATE VIEW collectorQueryDependencyTree AS
|
|
WITH RECURSIVE collectorQueryDependencyTree AS (
|
|
SELECT cq.id as collectorId, aqc.id as queryId, aqc.type, aqc.requiredIds, aqc.activeVersion
|
|
FROM fullActiveQueries as aqc
|
|
LEFT JOIN (
|
|
SELECT DISTINCT c.id, array_agg(q.queryId) as queryIds
|
|
FROM collectors as c
|
|
LEFT JOIN collectorQueries as q ON c.id = q.collectorId
|
|
AND c.activeVersion >= q.addedVersion
|
|
and c.activeVersion < COALESCE(q.removedVersion, c.activeVersion + 1)
|
|
GROUP BY c.id
|
|
) as cq ON aqc.id = any(cq.queryIds)
|
|
|
|
UNION ALL
|
|
|
|
SELECT acq.collectorId, q.id as queryId, q.type, q.requiredIds, q.activeVersion
|
|
FROM fullActiveQueries as q
|
|
JOIN collectorQueryDependencyTree as acq on q.id = ANY(acq.requiredIds)
|
|
)
|
|
SELECT collectorId, queryId, type, activeVersion as queryVersion, requiredIds::uuid[]
|
|
FROM collectorQueryDependencyTree; |