2025-01-29 11:52:37 +00:00
|
|
|
-- name: ListQueryRequirementValues :many
|
2025-02-11 15:22:59 +00:00
|
|
|
WITH reqQueries as (
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT av.queryId, av.activeVersion, q.type
|
2025-01-29 11:52:37 +00:00
|
|
|
FROM requiredQueries as rq
|
2025-02-20 19:02:44 +00:00
|
|
|
JOIN queryCurrentActiveVersions as av on av.queryId = rq.requiredQueryId
|
|
|
|
|
JOIN queries as q on q.id = av.queryId
|
2025-02-11 15:22:59 +00:00
|
|
|
WHERE rq.queryId = @queryId
|
2025-02-14 18:43:26 +00:00
|
|
|
and isInVersion(@version, rq.addedVersion, rq.removedVersion)
|
2025-02-11 15:22:59 +00:00
|
|
|
),
|
2025-02-14 10:56:24 +00:00
|
|
|
docs as (
|
|
|
|
|
SELECT id, jobId
|
|
|
|
|
FROM documents
|
|
|
|
|
WHERE id = @documentId
|
|
|
|
|
),
|
2025-02-11 15:22:59 +00:00
|
|
|
codeVersions as (
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT
|
2025-02-11 15:22:59 +00:00
|
|
|
d.id as documentId,
|
2025-02-20 19:02:44 +00:00
|
|
|
mcv.minCleanVersion,
|
|
|
|
|
mtv.minTextVersion
|
2025-02-14 10:56:24 +00:00
|
|
|
FROM docs as d
|
2025-02-20 19:02:44 +00:00
|
|
|
JOIN currentCollectorMinTextVersions as mtv on mtv.jobId = d.jobId
|
|
|
|
|
JOIN currentCollectorMinCleanVersions as mcv on mcv.jobId = d.jobId
|
2025-02-11 15:22:59 +00:00
|
|
|
),
|
|
|
|
|
latestVersions AS (
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT
|
|
|
|
|
r.id,
|
2025-02-11 15:22:59 +00:00
|
|
|
rq.queryId,
|
|
|
|
|
rq.type,
|
|
|
|
|
r.queryVersion,
|
2025-02-20 19:02:44 +00:00
|
|
|
r.textEntryId,
|
|
|
|
|
r.value,
|
2025-02-11 15:22:59 +00:00
|
|
|
ROW_NUMBER() OVER (
|
2025-02-20 19:02:44 +00:00
|
|
|
PARTITION BY r.queryId
|
|
|
|
|
ORDER BY r.id DESC
|
2025-02-11 15:22:59 +00:00
|
|
|
) as rowNumber
|
|
|
|
|
FROM reqQueries as rq
|
2025-02-20 19:02:44 +00:00
|
|
|
JOIN currentTextEntries as cte on cte.documentId = @documentId
|
2025-02-11 15:22:59 +00:00
|
|
|
LEFT JOIN results as r ON rq.queryId = r.queryId
|
|
|
|
|
and r.queryVersion = rq.activeVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
and cte.id = r.textEntryId
|
2025-02-11 15:22:59 +00:00
|
|
|
)
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT DISTINCT id, queryId, type, value
|
|
|
|
|
FROM latestVersions
|
|
|
|
|
WHERE rowNumber = 1;
|
2024-12-20 17:35:33 +00:00
|
|
|
|
2025-02-20 19:02:44 +00:00
|
|
|
-- name: AddResult :one
|
|
|
|
|
INSERT INTO results (queryId, value, textEntryId, queryVersion) VALUES ($1, $2, $3, $4) returning id;
|
|
|
|
|
|
|
|
|
|
-- name: AddResultDependency :exec
|
|
|
|
|
INSERT INTO resultDependencies (resultId, requiredResultId) VALUES ($1, $2);
|
2025-01-29 11:52:37 +00:00
|
|
|
|
|
|
|
|
-- name: GetResultValueWithVersion :one
|
2025-02-20 19:02:44 +00:00
|
|
|
WITH doc as (
|
|
|
|
|
SELECT id, jobId
|
|
|
|
|
FROM documents
|
|
|
|
|
WHERE id = @documentId
|
|
|
|
|
)
|
|
|
|
|
SELECT r.id, r.value
|
|
|
|
|
FROM doc as d
|
|
|
|
|
JOIN currentTextEntries as cte on cte.documentId = d.id
|
|
|
|
|
LEFT JOIN results as r
|
|
|
|
|
on r.queryId = @queryId
|
|
|
|
|
and r.queryVersion = @queryVersion
|
|
|
|
|
and r.textEntryId = cte.id;
|
2025-01-29 11:52:37 +00:00
|
|
|
|
2025-02-11 15:22:59 +00:00
|
|
|
-- name: ListUnsyncedNoDepsQueriesByDocId :many
|
|
|
|
|
WITH docs as (
|
|
|
|
|
SELECT id, jobId from documents where id = $1
|
|
|
|
|
),
|
|
|
|
|
unsyncedQueries AS (
|
2025-02-20 19:02:44 +00:00
|
|
|
SELECT DISTINCT dt.queryId, dt.requiredIds
|
2025-02-11 15:22:59 +00:00
|
|
|
from docs as d
|
|
|
|
|
JOIN collectorQueryDependencyTree as dt on d.jobId = dt.jobId
|
2025-02-20 19:02:44 +00:00
|
|
|
JOIN currentTextEntries as cte on cte.documentId = d.id
|
|
|
|
|
LEFT JOIN results as r
|
|
|
|
|
on r.queryId = dt.queryId
|
2025-01-29 11:52:37 +00:00
|
|
|
and r.queryVersion = dt.queryVersion
|
2025-02-20 19:02:44 +00:00
|
|
|
and cte.id = r.textEntryId
|
2025-02-11 15:22:59 +00:00
|
|
|
where r.value is null
|
2025-01-29 11:52:37 +00:00
|
|
|
)
|
2025-02-11 15:22:59 +00:00
|
|
|
SELECT DISTINCT queryId FROM unsyncedQueries as baseuq
|
|
|
|
|
WHERE NOT EXISTS (
|
|
|
|
|
SELECT 1 FROM unsyncedQueries as uq WHERE uq.queryId = any(baseuq.requiredIds)
|
|
|
|
|
);
|