Merged in feature/entitylogs (pull request #67)

Query Version Update
This commit is contained in:
Michael McGuinness
2025-02-14 18:43:26 +00:00
parent a6991079de
commit 750abe1be3
25 changed files with 424 additions and 209 deletions
+11 -8
View File
@@ -6,14 +6,13 @@ SELECT * FROM fullActiveQueries WHERE id = $1;
-- name: GetQueryWithVersion :one
WITH query as (
SELECT id, type, activeVersion, latestVersion FROM queries WHERE id = @id
SELECT id, type FROM queries WHERE id = @id
),
config as (
SELECT c.queryId, c.config
FROM query AS q
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
and @version >= c.addedVersion
and (c.removedVersion is null or @version < c.removedVersion)
and isInVersion(@version, c.addedVersion, c.removedVersion)
),
requiredIds as (
SELECT r.queryId,
@@ -22,16 +21,17 @@ requiredIds as (
as requiredIds
FROM query AS q
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
and @version >= r.addedVersion
and (r.removedVersion is null or @version < r.removedVersion)
and isInVersion(@version, r.addedVersion, r.removedVersion)
GROUP BY r.queryId
)
SELECT DISTINCT q.id, q.type, q.activeVersion, q.latestVersion, c.config,
SELECT DISTINCT q.id, q.type, coalesce(av.id, 0) as activeVersion, coalesce(lv.id, 0) as latestVersion, c.config,
coalesce(
r.requiredIds,
array[]::uuid[]
)::uuid[] as requiredIds
FROM query AS q
LEFT JOIN queryCurrentActiveVersions as av on q.id = av.queryId
LEFT JOIN queryLatestVersions as lv on lv.queryId = q.id
LEFT JOIN config AS c ON q.id = c.queryId
LEFT JOIN requiredIds AS r ON q.id = r.queryId;
@@ -44,8 +44,11 @@ SELECT * FROM fullActiveQueries WHERE id = any($1);
-- name: CreateQuery :one
INSERT INTO queries (type) VALUES ($1) RETURNING id;
-- name: UpdateQuery :exec
UPDATE queries SET activeVersion = $1, latestVersion = $2 WHERE id = $3;
-- name: AddLatestQueryVersion :exec
INSERT INTO queryVersions (queryId) VALUES ($1);
-- name: AddActiveQueryVersion :exec
INSERT INTO queryActiveVersions (queryId, versionId) VALUES ($1, $2);
-- name: AddRequiredQuery :exec
INSERT INTO requiredQueries (queryId, requiredQueryId, addedVersion) VALUES ($1, $2, $3);