can grab all queries required to fulfill a collector
This commit is contained in:
@@ -0,0 +1 @@
|
||||
DROP TYPE queryType;
|
||||
@@ -0,0 +1 @@
|
||||
CREATE TYPE queryType AS ENUM ('json_extractor');
|
||||
@@ -2,5 +2,5 @@ CREATE TABLE queries (
|
||||
id uuid primary key,
|
||||
latestVersion int not null default 1,
|
||||
activeVersion int not null default 1,
|
||||
type QueryType not null
|
||||
type queryType not null
|
||||
);
|
||||
@@ -1,6 +1,8 @@
|
||||
CREATE TABLE collectors (
|
||||
id uuid primary key,
|
||||
jobId uuid not null,
|
||||
minCleanVersion int not null default 1,
|
||||
minTextVersion int not null default 1,
|
||||
latestVersion int not null default 1,
|
||||
activeVersion int not null default 1
|
||||
);
|
||||
@@ -7,5 +7,5 @@ CREATE TABLE collectorQueries (
|
||||
removedVersion int,
|
||||
foreign key (queryId) references queries(id),
|
||||
foreign key (collectorId) references collectors(id),
|
||||
unique (collectorId, name, removedAt)
|
||||
unique (collectorId, name, removedVersion)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE results;
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE results (
|
||||
id uuid primary key,
|
||||
queryId uuid not null,
|
||||
documentId uuid not null,
|
||||
value TEXT,
|
||||
cleanVersion int not null,
|
||||
textVersion int not null,
|
||||
queryVersion int not null,
|
||||
foreign key (queryId) references queries(id),
|
||||
unique (queryId, documentId, cleanVersion, textVersion, queryVersion)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE requiredQueries;
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE requiredQueries (
|
||||
id uuid primary key,
|
||||
queryId uuid not null,
|
||||
requiredQueryId uuid not null,
|
||||
addedVersion int not null,
|
||||
removedVersion int,
|
||||
foreign key (queryId) references queries(id),
|
||||
foreign key (requiredQueryId) references queries(id),
|
||||
unique (queryId, requiredQueryId, removedVersion)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP VIEW activeQueryRequirements;
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE VIEW activeQueryRequirements AS
|
||||
SELECT q.id, q.type, q.activeVersion, rq.requiredQueryId
|
||||
FROM queries q
|
||||
JOIN requiredQueries rq ON q.id = rq.queryId
|
||||
WHERE q.activeVersion >= rq.addedVersion AND q.activeVersion < COALESCE(rq.removedVersion, q.activeVersion + 1);
|
||||
@@ -0,0 +1 @@
|
||||
DROP VIEW activeCollectorQueries;
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE VIEW activeCollectorQueries AS
|
||||
SELECT c.id, c.jobId, c.minCleanVersion, c.minTextVersion, c.activeVersion, cq.queryId
|
||||
FROM collectors c
|
||||
JOIN collectorQueries cq ON c.id = cq.collectorId
|
||||
WHERE c.activeVersion >= cq.addedVersion AND c.activeVersion < COALESCE(cq.removedVersion, c.activeVersion + 1);
|
||||
@@ -0,0 +1 @@
|
||||
DROP VIEW collectorQueryDependencyTree;
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE VIEW collectorQueryDependencyTree (id, jobId, type, requiredQueryId, queryVersion, minCleanVersion, minTextVersion) AS
|
||||
WITH RECURSIVE collectorQueryDependencyTree AS (
|
||||
SELECT aqc.id, cq.jobId, aqc.type, aqc.requiredQueryId, aqc.activeVersion as queryVersion, cq.minCleanVersion, cq.minTextVersion
|
||||
FROM activeQueryRequirements aqc
|
||||
JOIN activeCollectorQueries cq ON cq.queryId = aqc.id
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT q.id, acq.jobId, q.type, q.requiredQueryId, q.activeVersion as queryVersion, acq.minCleanVersion, acq.minTextVersion
|
||||
FROM activeQueryRequirements q
|
||||
JOIN collectorQueryDependencyTree acq on q.id = acq.requiredQueryId
|
||||
)
|
||||
SELECT DISTINCT * FROM collectorQueryDependencyTree;
|
||||
Reference in New Issue
Block a user