0df3d16976
Query Version Sync Runner * testing * queryversiosyncworking * update * tests * fixtests
46 lines
1.7 KiB
SQL
46 lines
1.7 KiB
SQL
CREATE VIEW fullActiveQueries AS
|
|
WITH config as (
|
|
SELECT c.queryId, c.config
|
|
FROM queries AS q
|
|
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
|
and q.activeVersion >= c.addedVersion
|
|
and (c.removedVersion is null or q.activeVersion < c.removedVersion)
|
|
),
|
|
requiredIds as (
|
|
SELECT r.queryId,
|
|
ARRAY_AGG(DISTINCT r.requiredQueryId)
|
|
FILTER (WHERE r.requiredQueryId != '00000000-0000-0000-0000-000000000000')::uuid[]
|
|
as requiredIds
|
|
FROM queries AS q
|
|
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
|
and q.activeVersion >= r.addedVersion
|
|
and (r.removedVersion is null or q.activeVersion < r.removedVersion)
|
|
GROUP BY r.queryId
|
|
)
|
|
SELECT DISTINCT q.id, q.type, q.activeVersion, q.latestVersion, c.config,
|
|
coalesce(
|
|
r.requiredIds,
|
|
array[]::uuid[]
|
|
)::uuid[] as requiredIds
|
|
FROM queries AS q
|
|
LEFT JOIN config AS c ON q.id = c.queryId
|
|
LEFT JOIN requiredIds AS r ON q.id = r.queryId;
|
|
|
|
CREATE VIEW queryActiveDependencies AS
|
|
WITH RECURSIVE queryActiveDependencies AS (
|
|
SELECT q.id, r.requiredQueryId
|
|
FROM queries AS q
|
|
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
|
and q.activeVersion >= r.addedVersion
|
|
and q.activeVersion < COALESCE(r.removedVersion, q.activeVersion + 1)
|
|
|
|
UNION ALL
|
|
|
|
SELECT qd.id, r.requiredQueryId
|
|
FROM queries AS q
|
|
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
|
and q.activeVersion >= r.addedVersion
|
|
and q.activeVersion < COALESCE(r.removedVersion, q.activeVersion + 1)
|
|
JOIN queryActiveDependencies as qd on q.id = qd.requiredQueryId
|
|
)
|
|
SELECT DISTINCT id, requiredQueryId FROM queryActiveDependencies; |