Merged in feature/textextract (pull request #108)
Start adding Textract + UUID changes * base * startclient * ts * short * tests
This commit is contained in:
@@ -0,0 +1 @@
|
||||
diagram.png
|
||||
@@ -0,0 +1,13 @@
|
||||
# Database schema
|
||||
|
||||
To view this diagram live in vscode use the `https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid` extension.
|
||||
|
||||
You can also edit live with `https://mermaid.live`
|
||||
|
||||
This diagram should be updated manually when there are changes to the database schema.
|
||||
|
||||
To generate the diagram directly use the following command, in the root directory:
|
||||
|
||||
```bash
|
||||
docker run --rm -u $(id -u):$(id -g) -v $(pwd)/database:/data minlag/mermaid-cli:latest -i /data/diagram.mmd -o /data/diagram.png -w 2000 -H 2000
|
||||
```
|
||||
@@ -0,0 +1,145 @@
|
||||
erDiagram
|
||||
clients ||--o{ clientCanSync : "has"
|
||||
clients ||--o{ documents : "contains"
|
||||
clients ||--o{ collectorVersions : "has"
|
||||
clients ||--o{ collectorActiveVersions : "has current"
|
||||
clients ||--o{ collectorMinCleanVersions : "has"
|
||||
clients ||--o{ collectorMinTextVersions : "has"
|
||||
clients ||--o{ collectorQueries : "maps to"
|
||||
|
||||
documents ||--o{ documentEntries : "has"
|
||||
documents ||--o{ documentCleans : "has clean version"
|
||||
documentCleans ||--o{ documentTextExtractions : "has text extraction"
|
||||
documentTextExtractions ||--o{ results : "produces"
|
||||
|
||||
queries ||--o{ queryVersions : "has"
|
||||
queries ||--o{ queryActiveVersions : "has current"
|
||||
queries ||--o{ requiredQueries : "requires"
|
||||
queries ||--o{ queryConfigs : "configured by"
|
||||
queries ||--o{ collectorQueries : "used in"
|
||||
queries ||--o{ results : "generates"
|
||||
|
||||
results ||--o{ resultDependencies : "depends on"
|
||||
|
||||
clients {
|
||||
uuid id PK
|
||||
TEXT name
|
||||
}
|
||||
|
||||
clientCanSync {
|
||||
uuid id PK
|
||||
uuid clientId FK
|
||||
boolean canSync
|
||||
}
|
||||
|
||||
documents {
|
||||
uuid id PK
|
||||
uuid clientId FK
|
||||
text hash
|
||||
}
|
||||
|
||||
documentEntries {
|
||||
uuid id PK
|
||||
uuid documentId FK
|
||||
text bucket
|
||||
text key
|
||||
}
|
||||
|
||||
documentCleans {
|
||||
uuid id PK
|
||||
uuid documentId FK
|
||||
int version
|
||||
text bucket
|
||||
text key
|
||||
}
|
||||
|
||||
documentTextExtractions {
|
||||
uuid id PK
|
||||
uuid cleanEntryId FK
|
||||
int version
|
||||
text bucket
|
||||
text key
|
||||
}
|
||||
|
||||
queries {
|
||||
uuid id PK
|
||||
queryType type
|
||||
}
|
||||
|
||||
queryVersions {
|
||||
uuid queryId FK
|
||||
int id
|
||||
timestamp addedAt
|
||||
}
|
||||
|
||||
queryActiveVersions {
|
||||
uuid id PK
|
||||
uuid queryId FK
|
||||
int versionId FK
|
||||
}
|
||||
|
||||
requiredQueries {
|
||||
uuid id PK
|
||||
uuid queryId FK
|
||||
uuid requiredQueryId FK
|
||||
int addedVersion FK
|
||||
int removedVersion FK
|
||||
}
|
||||
|
||||
queryConfigs {
|
||||
uuid id PK
|
||||
uuid queryId FK
|
||||
jsonb config
|
||||
int addedVersion FK
|
||||
int removedVersion FK
|
||||
}
|
||||
|
||||
collectorVersions {
|
||||
uuid clientId FK
|
||||
int id
|
||||
timestamp addedAt
|
||||
}
|
||||
|
||||
collectorActiveVersions {
|
||||
uuid id PK
|
||||
uuid clientId FK
|
||||
int versionId FK
|
||||
}
|
||||
|
||||
collectorMinCleanVersions {
|
||||
uuid id PK
|
||||
uuid clientId FK
|
||||
int versionId
|
||||
int addedVersion FK
|
||||
int removedVersion FK
|
||||
}
|
||||
|
||||
collectorMinTextVersions {
|
||||
uuid id PK
|
||||
uuid clientId FK
|
||||
int versionId
|
||||
int addedVersion FK
|
||||
int removedVersion FK
|
||||
}
|
||||
|
||||
collectorQueries {
|
||||
uuid id PK
|
||||
uuid clientId FK
|
||||
varchar name
|
||||
uuid queryId FK
|
||||
int addedVersion FK
|
||||
int removedVersion FK
|
||||
}
|
||||
|
||||
results {
|
||||
uuid id PK
|
||||
uuid textEntryId FK
|
||||
uuid queryId FK
|
||||
TEXT value
|
||||
int queryVersion
|
||||
}
|
||||
|
||||
resultDependencies {
|
||||
uuid resultId FK
|
||||
uuid requiredResultId FK
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package migrations
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"embed"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"path"
|
||||
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/database"
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
_ "github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
"github.com/golang-migrate/migrate/v4/source/iofs"
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
@@ -43,17 +44,21 @@ func createDB(cfg database.ConfigProvider) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, cfg serviceconfig.ConfigProvider) error {
|
||||
//go:embed migrations/*.up.sql
|
||||
var migrations embed.FS
|
||||
|
||||
func RunMigrations(ctx context.Context, cfg serviceconfig.ConfigProvider) error {
|
||||
err := createDB(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
migPath := "file://" + path.Join(cfg.GetBasePath(), "database/migrations")
|
||||
m, err := migrate.New(
|
||||
migPath,
|
||||
cfg.GetDBURI(),
|
||||
)
|
||||
source, err := iofs.New(migrations, "migrations")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m, err := migrate.NewWithSourceInstance("iofs", source, cfg.GetDBURI())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create migrate instance: %v", err)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
DROP EXTENSION "pgcrypto";
|
||||
@@ -0,0 +1,34 @@
|
||||
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
||||
|
||||
create or replace function uuid_generate_v7()
|
||||
returns uuid
|
||||
as $$
|
||||
select encode(
|
||||
set_bit(
|
||||
set_bit(
|
||||
overlay(uuid_send(gen_random_uuid())
|
||||
placing substring(int8send(floor(extract(epoch from clock_timestamp()) * 1000)::bigint) from 3)
|
||||
from 1 for 6
|
||||
),
|
||||
52, 1
|
||||
),
|
||||
53, 1
|
||||
),
|
||||
'hex')::uuid;
|
||||
$$
|
||||
language SQL
|
||||
volatile;
|
||||
|
||||
CREATE FUNCTION isInVersion(
|
||||
_version int,
|
||||
_addedVersion int,
|
||||
_removedVersion int
|
||||
)
|
||||
RETURNS boolean as $$
|
||||
BEGIN
|
||||
RETURN _version is null OR (
|
||||
_version >= _addedVersion AND
|
||||
(_removedVersion is null OR _version < _removedVersion)
|
||||
);
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
@@ -0,0 +1,7 @@
|
||||
DROP TABLE queries;
|
||||
|
||||
DROP TYPE queryType;
|
||||
|
||||
DROP TABLE requiredQueries;
|
||||
|
||||
DROP TABLE queryConfigs;
|
||||
@@ -0,0 +1,79 @@
|
||||
CREATE TYPE queryType AS ENUM ('context_full', 'json_extractor');
|
||||
|
||||
CREATE TABLE queries (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
type queryType not null
|
||||
);
|
||||
|
||||
CREATE TABLE queryVersions (
|
||||
queryId uuid not null,
|
||||
id int not null,
|
||||
addedAt timestamp not null default current_timestamp,
|
||||
primary key (id, queryId),
|
||||
foreign key (queryId) references queries(id)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION setQueryVersionNumber()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
SELECT COALESCE(MAX(id), 0) + 1
|
||||
INTO NEW.id
|
||||
FROM queryVersions
|
||||
WHERE queryId = NEW.queryId;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER setQueryVersionNumberTrigger
|
||||
BEFORE INSERT ON queryVersions
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION setQueryVersionNumber();
|
||||
|
||||
CREATE TABLE queryActiveVersions (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
queryId uuid not null,
|
||||
versionId int not null,
|
||||
foreign key (queryId, versionId) references queryVersions(queryId, id)
|
||||
);
|
||||
|
||||
CREATE TABLE requiredQueries (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
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),
|
||||
foreign key (queryId, addedVersion) references queryVersions(queryId, id),
|
||||
foreign key (queryId, removedVersion) references queryVersions(queryId, id),
|
||||
unique (queryId, requiredQueryId, removedVersion)
|
||||
);
|
||||
|
||||
CREATE TABLE queryConfigs (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
queryId uuid not null,
|
||||
config jsonb not null,
|
||||
addedVersion int not null,
|
||||
removedVersion int,
|
||||
foreign key (queryId) references queries(id),
|
||||
foreign key (queryId, addedVersion) references queryVersions(queryId, id),
|
||||
foreign key (queryId, removedVersion) references queryVersions(queryId, id),
|
||||
unique (queryId, removedVersion)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION removeQueryConfig()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
UPDATE queryConfigs
|
||||
SET removedVersion = NEW.addedVersion
|
||||
WHERE queryId = NEW.queryId and removedVersion is null;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER removeQueryConfigTrigger
|
||||
BEFORE INSERT ON queryConfigs
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION removeQueryConfig();
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE clients;
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE clients (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
externalId varchar(255) not null,
|
||||
name TEXT not null,
|
||||
UNIQUE (name),
|
||||
UNIQUE (externalId)
|
||||
);
|
||||
|
||||
CREATE TABLE clientCanSync (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
clientId uuid not null,
|
||||
canSync boolean not null,
|
||||
foreign key (clientId) references clients(id)
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
DROP TABLE collectorQueries;
|
||||
|
||||
DROP TABLE collectors;
|
||||
@@ -0,0 +1,99 @@
|
||||
CREATE TABLE collectorVersions (
|
||||
clientId uuid not null,
|
||||
id int not null,
|
||||
addedAt timestamp not null default current_timestamp,
|
||||
foreign key (clientId) references clients(id),
|
||||
primary key (id, clientId)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION setCollectorVersionNumber()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
SELECT COALESCE(MAX(id), 0) + 1
|
||||
INTO NEW.id
|
||||
FROM collectorVersions
|
||||
WHERE clientId = NEW.clientId;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER setCollectorVersionNumberTrigger
|
||||
BEFORE INSERT ON collectorVersions
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION setCollectorVersionNumber();
|
||||
|
||||
CREATE TABLE collectorActiveVersions (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
clientId uuid not null,
|
||||
versionId int not null,
|
||||
foreign key (clientId, versionId) references collectorVersions(clientId, id)
|
||||
);
|
||||
|
||||
CREATE TABLE collectorMinCleanVersions (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
clientId uuid not null,
|
||||
versionId bigint not null,
|
||||
addedVersion int not null,
|
||||
removedVersion int,
|
||||
foreign key (clientId, addedVersion) references collectorVersions(clientId, id),
|
||||
foreign key (clientId, removedVersion) references collectorVersions(clientId, id),
|
||||
foreign key (clientId) references clients(id)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION removeMinCleanVersion()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
UPDATE collectorMinCleanVersions
|
||||
SET removedVersion = NEW.addedVersion
|
||||
WHERE clientId = NEW.clientId and removedVersion is null;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER removeMinCleanVersionTrigger
|
||||
BEFORE INSERT ON collectorMinCleanVersions
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION removeMinCleanVersion();
|
||||
|
||||
CREATE TABLE collectorMinTextVersions (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
clientId uuid not null,
|
||||
versionId bigint not null,
|
||||
addedVersion int not null,
|
||||
removedVersion int,
|
||||
foreign key (clientId, addedVersion) references collectorVersions(clientId, id),
|
||||
foreign key (clientId, removedVersion) references collectorVersions(clientId, id),
|
||||
foreign key (clientId) references clients(id)
|
||||
);
|
||||
|
||||
CREATE OR REPLACE FUNCTION removeMinTextVersion()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
UPDATE collectorMinTextVersions
|
||||
SET removedVersion = NEW.addedVersion
|
||||
WHERE clientId = NEW.clientId and removedVersion is null;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER removeMinTextVersionTrigger
|
||||
BEFORE INSERT ON collectorMinTextVersions
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION removeMinTextVersion();
|
||||
|
||||
CREATE TABLE collectorQueries (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
clientId uuid not null,
|
||||
name varchar(255) not null,
|
||||
queryId uuid not null,
|
||||
addedVersion int not null,
|
||||
removedVersion int,
|
||||
foreign key (queryId) references queries(id),
|
||||
foreign key (clientId) references clients(id),
|
||||
foreign key (clientId, addedVersion) references collectorVersions(clientId, id),
|
||||
foreign key (clientId, removedVersion) references collectorVersions(clientId, id),
|
||||
unique (clientId, name, removedVersion)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE documents;
|
||||
@@ -0,0 +1,67 @@
|
||||
CREATE TABLE documents (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
clientId uuid not null,
|
||||
hash text not null,
|
||||
foreign key (clientId) references clients(id),
|
||||
unique(clientId, hash)
|
||||
);
|
||||
|
||||
CREATE TABLE documentEntries (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
documentId uuid not null,
|
||||
bucket text not null,
|
||||
key text not null,
|
||||
foreign key (documentId) references documents(id)
|
||||
);
|
||||
|
||||
CREATE TYPE cleanFailType AS ENUM (
|
||||
'invalid_mimetype',
|
||||
'invalid_read',
|
||||
'invalid_read_pages',
|
||||
'zero_page_count',
|
||||
'large_page_count',
|
||||
'large_file',
|
||||
'small_dimensions',
|
||||
'large_dimensions',
|
||||
'small_dpi',
|
||||
'large_dpi'
|
||||
);
|
||||
CREATE TYPE cleanMimeType AS ENUM ('application/pdf');
|
||||
|
||||
CREATE TABLE documentCleans (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
documentId uuid not null,
|
||||
bucket text,
|
||||
key text,
|
||||
mimetype cleanMimeType,
|
||||
fail cleanFailType,
|
||||
foreign key (documentId) references documents(id),
|
||||
CONSTRAINT bucket_and_key_together CHECK ((bucket IS NULL) = (key IS NULL) and (bucket is null) = (mimetype is null)),
|
||||
CONSTRAINT location_xor_fail CHECK (
|
||||
(bucket IS NOT NULL) != (fail IS NOT NULL)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE TABLE documentCleanEntries (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
cleanId uuid not null,
|
||||
version bigint not null,
|
||||
foreign key (cleanId) references documentCleans(id)
|
||||
);
|
||||
|
||||
CREATE TABLE documentTextExtractions (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
cleanEntryId uuid not null,
|
||||
bucket text not null,
|
||||
key text not null,
|
||||
hash text not null,
|
||||
foreign key (cleanEntryId) references documentCleans(id),
|
||||
unique(cleanEntryId, hash)
|
||||
);
|
||||
|
||||
CREATE TABLE documentTextExtractionEntries (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
textId uuid not null,
|
||||
version bigint not null,
|
||||
foreign key (textId) references documentTextExtractions(id)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP TABLE results;
|
||||
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE results (
|
||||
id uuid primary key DEFAULT uuid_generate_v7(),
|
||||
textEntryId uuid not null,
|
||||
queryId uuid not null,
|
||||
value TEXT not null,
|
||||
queryVersion int not null,
|
||||
foreign key (queryId) references queries(id),
|
||||
foreign key (textEntryId) references documentTextExtractions(id),
|
||||
foreign key (queryId, queryVersion) references queryVersions(queryId, id)
|
||||
);
|
||||
|
||||
CREATE TABLE resultDependencies (
|
||||
resultId uuid not null,
|
||||
requiredResultId uuid not null,
|
||||
foreign key (resultId) references results(id),
|
||||
foreign key (requiredResultId) references results(id),
|
||||
CONSTRAINT result_not_self_dependent CHECK (resultId != requiredResultId)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
DROP VIEW fullActiveQueries;
|
||||
@@ -0,0 +1,71 @@
|
||||
CREATE VIEW queryCurrentActiveVersions as
|
||||
SELECT DISTINCT
|
||||
q.id as queryId,
|
||||
coalesce(
|
||||
(FIRST_VALUE(av.versionId) OVER (PARTITION BY q.id ORDER BY av.id DESC)),
|
||||
0
|
||||
)::int as activeVersion
|
||||
FROM queries AS q
|
||||
LEFT JOIN queryActiveVersions as av on av.queryId = q.id;
|
||||
|
||||
CREATE VIEW queryLatestVersions as
|
||||
SELECT
|
||||
q.id as queryId,
|
||||
coalesce(max(v.id), 0)::int as latestVersion
|
||||
FROM queries AS q
|
||||
LEFT JOIN queryVersions as v on v.queryId = q.id
|
||||
GROUP BY q.id;
|
||||
|
||||
CREATE VIEW queryCurrentConfigs as
|
||||
SELECT av.queryId, c.config
|
||||
FROM queryCurrentActiveVersions as av
|
||||
LEFT JOIN queryConfigs AS c ON av.queryId = c.queryId
|
||||
and isInVersion(av.activeVersion, c.addedVersion, c.removedVersion);
|
||||
|
||||
CREATE VIEW queryCurrentRequiredIds as
|
||||
SELECT DISTINCT av.queryId, r.requiredQueryId
|
||||
FROM queryCurrentActiveVersions as av
|
||||
LEFT JOIN requiredQueries AS r ON av.queryId = r.queryId
|
||||
and isInVersion(av.activeVersion, r.addedVersion, r.removedVersion);
|
||||
|
||||
CREATE VIEW queryCurrentRequiredIdsAGG as
|
||||
SELECT queryId,
|
||||
coalesce(
|
||||
ARRAY_AGG(DISTINCT requiredQueryId)
|
||||
FILTER (WHERE requiredQueryId != '00000000-0000-0000-0000-000000000000')::uuid[],
|
||||
array[]::uuid[]
|
||||
)::uuid[] as requiredIds
|
||||
FROM queryCurrentRequiredIds
|
||||
GROUP BY queryId;
|
||||
|
||||
CREATE VIEW fullActiveQueries AS
|
||||
SELECT DISTINCT q.id, q.type, av.activeVersion, lv.latestVersion, c.config, r.requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryCurrentActiveVersions as av on q.id = av.queryId
|
||||
JOIN queryLatestVersions as lv on lv.queryId = q.id
|
||||
JOIN queryCurrentConfigs AS c ON q.id = c.queryId
|
||||
JOIN queryCurrentRequiredIdsAGG AS r ON q.id = r.queryId;
|
||||
|
||||
CREATE VIEW queryActiveDependencies AS
|
||||
WITH RECURSIVE queryActiveDependencies(queryId, requiredQueryId, path, cycle) AS (
|
||||
SELECT
|
||||
queryId,
|
||||
requiredQueryId,
|
||||
ARRAY[queryId, requiredQueryId]::uuid[] AS path,
|
||||
false AS cycle
|
||||
FROM queryCurrentRequiredIds
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
q.queryId,
|
||||
qd.requiredQueryId,
|
||||
path || qd.requiredQueryId,
|
||||
qd.requiredQueryId = ANY(path) AS cycle
|
||||
FROM queryCurrentRequiredIds as q
|
||||
JOIN queryActiveDependencies as qd ON q.queryId = qd.requiredQueryId
|
||||
WHERE NOT qd.cycle -- Stop if we detect a cycle
|
||||
)
|
||||
SELECT DISTINCT queryId as id, requiredQueryId
|
||||
FROM queryActiveDependencies
|
||||
WHERE NOT cycle;
|
||||
@@ -0,0 +1,3 @@
|
||||
DROP VIEW fullActiveCollectors;
|
||||
|
||||
DROP VIEW collectorQueryDependencyTree;
|
||||
@@ -0,0 +1,77 @@
|
||||
CREATE VIEW collectorCurrentActiveVersions as
|
||||
SELECT DISTINCT
|
||||
j.id as clientId,
|
||||
coalesce(
|
||||
(FIRST_VALUE(v.versionId) OVER (PARTITION BY j.id ORDER BY v.id DESC)),
|
||||
0
|
||||
)::int as activeVersion
|
||||
FROM clients as j
|
||||
LEFT JOIN collectorActiveVersions as v on v.clientId = j.id;
|
||||
|
||||
CREATE VIEW collectorLatestVersions as
|
||||
SELECT
|
||||
j.id as clientId,
|
||||
coalesce(max(v.id), 0)::int as latestVersion
|
||||
FROM clients as j
|
||||
LEFT JOIN collectorVersions as v on v.clientId = j.id
|
||||
GROUP BY j.id;
|
||||
|
||||
CREATE VIEW currentCollectorMinTextVersions as
|
||||
SELECT DISTINCT
|
||||
av.clientId,
|
||||
coalesce(ctv.versionId, 0) as minTextVersion
|
||||
FROM collectorCurrentActiveVersions as av
|
||||
LEFT JOIN collectorMinTextVersions AS ctv ON av.clientId = ctv.clientId
|
||||
and isInVersion(av.activeVersion, ctv.addedVersion, ctv.removedVersion);
|
||||
|
||||
CREATE VIEW currentCollectorMinCleanVersions as
|
||||
SELECT DISTINCT
|
||||
av.clientId,
|
||||
coalesce(ctv.versionId, 0) as minCleanVersion
|
||||
FROM collectorCurrentActiveVersions as av
|
||||
LEFT JOIN collectorMinCleanVersions AS ctv ON av.clientId = ctv.clientId
|
||||
and isInVersion(av.activeVersion, ctv.addedVersion, ctv.removedVersion);
|
||||
|
||||
CREATE VIEW currentCollectorQueries as
|
||||
SELECT DISTINCT
|
||||
av.clientId,
|
||||
q.name,
|
||||
q.queryId
|
||||
FROM collectorCurrentActiveVersions as av
|
||||
LEFT JOIN collectorQueries AS q ON av.clientId = q.clientId
|
||||
and isInVersion(av.activeVersion, q.addedVersion, q.removedVersion);
|
||||
|
||||
CREATE VIEW currentCollectorQueriesJSONAGG as
|
||||
SELECT DISTINCT
|
||||
clientId,
|
||||
jsonb_object_agg(name, queryId) FILTER (WHERE name is not null) AS fields
|
||||
FROM currentCollectorQueries
|
||||
GROUP BY clientId;
|
||||
|
||||
CREATE VIEW fullActiveCollectors AS
|
||||
SELECT DISTINCT av.clientId,
|
||||
ccv.minCleanVersion, ctv.minTextVersion,
|
||||
av.activeVersion, lv.latestVersion,
|
||||
q.fields
|
||||
FROM collectorCurrentActiveVersions as av
|
||||
JOIN collectorLatestVersions as lv on lv.clientId = av.clientId
|
||||
JOIN currentCollectorMinCleanVersions AS ccv ON av.clientId = ccv.clientId
|
||||
JOIN currentCollectorMinTextVersions AS ctv ON av.clientId = ctv.clientId
|
||||
JOIN currentCollectorQueriesJSONAGG AS q ON av.clientId = q.clientId;
|
||||
|
||||
CREATE VIEW collectorQueryDependencyTree AS
|
||||
WITH RECURSIVE collectorQueryDependencyTree AS (
|
||||
SELECT cq.clientId, cq.queryId, ri.requiredIds
|
||||
FROM currentCollectorQueries as cq
|
||||
JOIN queryCurrentRequiredIdsAGG as ri on cq.queryId = ri.queryId
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT acq.clientId, q.queryId, q.requiredIds
|
||||
FROM queryCurrentRequiredIdsAGG as q
|
||||
JOIN collectorQueryDependencyTree as acq on q.queryId = ANY(acq.requiredIds)
|
||||
)
|
||||
SELECT DISTINCT ct.clientId, ct.queryId, q.type, av.activeVersion as queryVersion, ct.requiredIds
|
||||
FROM collectorQueryDependencyTree as ct
|
||||
JOIN queryCurrentActiveVersions as av on ct.queryId = av.queryId
|
||||
JOIN queries as q on q.id = ct.queryId;
|
||||
@@ -0,0 +1 @@
|
||||
DROP VIEW listDocumentIDs;
|
||||
@@ -0,0 +1,203 @@
|
||||
CREATE OR REPLACE FUNCTION listDocumentIDs(
|
||||
_clientId uuid,
|
||||
_batchSize INTEGER,
|
||||
_offset INTEGER
|
||||
)
|
||||
RETURNS TABLE (id uuid, totalCount BIGINT) AS $$
|
||||
DECLARE
|
||||
totalCount BIGINT := 0;
|
||||
BEGIN
|
||||
SELECT COUNT(*)::BIGINT INTO totalCount FROM documents WHERE clientId = _clientId;
|
||||
|
||||
RETURN QUERY
|
||||
SELECT d.id, totalCount
|
||||
FROM documents as d
|
||||
WHERE d.clientId = _clientId
|
||||
ORDER BY d.id
|
||||
LIMIT _batchSize
|
||||
OFFSET _offset;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE VIEW currentCleanEntries as
|
||||
WITH RankedExtractions AS (
|
||||
SELECT
|
||||
dc.id,
|
||||
dc.documentId,
|
||||
dc.bucket,
|
||||
dc.key,
|
||||
dc.mimetype,
|
||||
dc.fail,
|
||||
dce.version,
|
||||
ROW_NUMBER() OVER (PARTITION BY dc.documentId ORDER BY dc.id DESC, dce.id DESC) as row_num
|
||||
FROM documents d
|
||||
JOIN currentCollectorMinCleanVersions ccv ON d.clientId = ccv.clientId
|
||||
JOIN documentCleans dc ON dc.documentId = d.id
|
||||
JOIN documentCleanEntries dce ON dc.id = dce.cleanId
|
||||
AND dce.version >= ccv.minCleanVersion
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
documentId,
|
||||
bucket,
|
||||
key,
|
||||
version,
|
||||
mimetype,
|
||||
fail
|
||||
FROM RankedExtractions
|
||||
WHERE row_num = 1;
|
||||
|
||||
CREATE VIEW currentTextEntries as
|
||||
WITH RankedExtractions AS (
|
||||
SELECT
|
||||
dte.id,
|
||||
cc.documentId,
|
||||
dte.bucket,
|
||||
dte.key,
|
||||
dte.hash,
|
||||
dtee.version,
|
||||
dte.cleanEntryId,
|
||||
ROW_NUMBER() OVER (PARTITION BY cc.documentId ORDER BY dte.id DESC) as row_num
|
||||
FROM documents d
|
||||
JOIN currentCleanEntries cc on cc.documentId = d.id
|
||||
JOIN currentCollectorMinTextVersions ctv ON ctv.clientId = d.clientId
|
||||
JOIN documentTextExtractions dte ON dte.cleanEntryId = cc.id
|
||||
JOIN documentTextExtractionEntries dtee on dte.id = dtee.textId
|
||||
AND dtee.version >= ctv.minTextVersion
|
||||
)
|
||||
SELECT
|
||||
id,
|
||||
documentId,
|
||||
bucket,
|
||||
key,
|
||||
version,
|
||||
hash,
|
||||
cleanEntryId
|
||||
FROM RankedExtractions
|
||||
WHERE row_num = 1;
|
||||
|
||||
CREATE VIEW currentClientCanSync as
|
||||
WITH RankedExtractions AS (
|
||||
SELECT
|
||||
ccs.clientId,
|
||||
ccs.canSync,
|
||||
ROW_NUMBER() OVER (PARTITION BY ccs.clientId ORDER BY ccs.id DESC) as row_num
|
||||
FROM clients c
|
||||
JOIN clientCanSync ccs on c.id = ccs.clientId
|
||||
)
|
||||
SELECT
|
||||
c.id as clientId,
|
||||
coalesce(r.canSync, false) as canSync
|
||||
FROM clients c
|
||||
LEFT JOIN RankedExtractions r on r.clientId = c.id and r.row_num = 1;
|
||||
|
||||
CREATE VIEW fullClients as
|
||||
SELECT c.id, c.externalId, c.name, cs.canSync
|
||||
FROM clients as c
|
||||
JOIN currentClientCanSync as cs on cs.clientId = c.id;
|
||||
|
||||
CREATE OR REPLACE FUNCTION listValidDocumentResults(doc_id uuid)
|
||||
RETURNS TABLE (documentId uuid, queryId uuid, resultId uuid, value text) AS $$
|
||||
DECLARE
|
||||
count_before INT;
|
||||
count_after INT;
|
||||
iterations INT := 0;
|
||||
BEGIN
|
||||
CREATE TEMPORARY TABLE allResults AS
|
||||
WITH
|
||||
docs AS (
|
||||
SELECT id as documentId, hash, clientId
|
||||
FROM documents
|
||||
WHERE id = doc_id
|
||||
),
|
||||
query_dependency_tree AS (
|
||||
WITH RECURSIVE query_deps AS (
|
||||
SELECT
|
||||
q.queryId,
|
||||
unnest(q.requiredIds) AS requiredId
|
||||
FROM collectorQueryDependencyTree AS q
|
||||
JOIN docs AS d ON d.clientId = q.clientId
|
||||
WHERE array_length(q.requiredIds, 1) > 0
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT
|
||||
qd.queryId,
|
||||
unnest(q.requiredIds) AS requiredId
|
||||
FROM query_deps qd
|
||||
JOIN collectorQueryDependencyTree q ON qd.requiredId = q.queryId
|
||||
WHERE array_length(q.requiredIds, 1) > 0
|
||||
)
|
||||
SELECT
|
||||
query_deps.queryId,
|
||||
array_agg(DISTINCT requiredId) AS all_required_ids
|
||||
FROM query_deps
|
||||
GROUP BY query_deps.queryId
|
||||
),
|
||||
docResults AS (
|
||||
SELECT
|
||||
d.documentId,
|
||||
q.queryId,
|
||||
r.id AS resultId,
|
||||
r.value,
|
||||
q.requiredIds as directRequiredIds,
|
||||
COALESCE(qdt.all_required_ids, ARRAY[]::uuid[]) AS allRequiredIds
|
||||
FROM docs AS d
|
||||
JOIN collectorQueryDependencyTree AS q ON q.clientId = d.clientId
|
||||
LEFT JOIN query_dependency_tree qdt ON q.queryId = qdt.queryId
|
||||
LEFT JOIN currentTextEntries AS tte ON tte.documentId = d.documentId
|
||||
LEFT JOIN results AS r
|
||||
ON q.queryId = r.queryId
|
||||
AND r.queryVersion = q.queryVersion
|
||||
AND tte.id = r.textEntryId
|
||||
WHERE r.value is not null
|
||||
)
|
||||
SELECT * FROM docResults dr;
|
||||
|
||||
CREATE TEMPORARY TABLE finalResults AS
|
||||
SELECT * from allResults where array_length(directRequiredIds, 1) is null;
|
||||
|
||||
SELECT COUNT(*) INTO count_before FROM finalResults;
|
||||
RAISE NOTICE 'Starting with % rows', count_before;
|
||||
|
||||
LOOP
|
||||
iterations := iterations + 1;
|
||||
|
||||
INSERT INTO finalResults
|
||||
SELECT dr.*
|
||||
FROM allResults dr
|
||||
WHERE
|
||||
dr.directRequiredIds IS NOT NULL
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM unnest(dr.directRequiredIds) AS req_id(queryId)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM allResults req_dr
|
||||
WHERE req_dr.queryId = req_id.queryId
|
||||
AND req_dr.resultId IN (SELECT fr.resultId FROM finalResults fr)
|
||||
AND exists (
|
||||
select 1 from resultDependencies rrd
|
||||
where dr.resultId = rrd.resultId
|
||||
and req_dr.resultId = rrd.requiredResultId
|
||||
)
|
||||
)
|
||||
)
|
||||
and dr.resultId NOT IN (SELECT fr.resultId FROM finalResults fr);
|
||||
|
||||
GET DIAGNOSTICS count_after = ROW_COUNT;
|
||||
RAISE NOTICE 'Iteration %: Additional Entries %',
|
||||
iterations, count_after;
|
||||
|
||||
IF count_after = 0 THEN
|
||||
EXIT;
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
RETURN QUERY SELECT tr.documentId, tr.queryId, tr.resultId, tr.value
|
||||
FROM finalResults tr;
|
||||
|
||||
DROP TABLE finalResults;
|
||||
DROP TABLE allResults;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
+4
-8
@@ -1,12 +1,10 @@
|
||||
package migrations_test
|
||||
package database_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database/migrations"
|
||||
migrations "queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/database"
|
||||
"queryorchestration/internal/test"
|
||||
@@ -23,14 +21,13 @@ func TestRunMigrations(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
})
|
||||
defer cleanup()
|
||||
|
||||
err := migrations.Run(ctx, cfg)
|
||||
err := migrations.RunMigrations(ctx, cfg)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -39,7 +36,6 @@ func TestRunMigrationsNoDB(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
cfg.SetDBConfig(&database.DBConfig{
|
||||
DBUser: "invalid_user",
|
||||
DBSecret: "invalid_pass",
|
||||
@@ -49,6 +45,6 @@ func TestRunMigrationsNoDB(t *testing.T) {
|
||||
DBNoSSL: true,
|
||||
})
|
||||
|
||||
err := migrations.Run(ctx, cfg)
|
||||
err := migrations.RunMigrations(ctx, cfg)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package migrations
|
||||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -1,94 +0,0 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func MustToDBUUIDArray(ids []uuid.UUID) []pgtype.UUID {
|
||||
dbid, err := ToDBUUIDArray(ids)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
return dbid
|
||||
}
|
||||
|
||||
func ToDBUUIDArray(ids []uuid.UUID) ([]pgtype.UUID, error) {
|
||||
dbIDs := []pgtype.UUID{}
|
||||
for _, id := range ids {
|
||||
uid, err := ToDBUUID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if uid.Valid {
|
||||
dbIDs = append(dbIDs, uid)
|
||||
}
|
||||
}
|
||||
|
||||
return dbIDs, nil
|
||||
}
|
||||
|
||||
func MustToDBUUID(id uuid.UUID) pgtype.UUID {
|
||||
dbid, err := ToDBUUID(id)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
return dbid
|
||||
}
|
||||
|
||||
func ToDBUUID(id uuid.UUID) (pgtype.UUID, error) {
|
||||
var dbID pgtype.UUID
|
||||
err := dbID.Scan(id.String())
|
||||
if err != nil {
|
||||
return dbID, err
|
||||
}
|
||||
|
||||
if id == uuid.Nil {
|
||||
dbID.Valid = false
|
||||
}
|
||||
|
||||
return dbID, nil
|
||||
}
|
||||
|
||||
func MustToUUID(dbid pgtype.UUID) uuid.UUID {
|
||||
id, err := ToUUID(dbid)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func ToUUID(id pgtype.UUID) (uuid.UUID, error) {
|
||||
return uuid.FromBytes(id.Bytes[:])
|
||||
}
|
||||
|
||||
func MustToUUIDArray(dbids []pgtype.UUID) []uuid.UUID {
|
||||
ids, err := ToUUIDArray(dbids)
|
||||
if err != nil {
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
func ToUUIDArray(dbIDs []pgtype.UUID) ([]uuid.UUID, error) {
|
||||
ids := []uuid.UUID{}
|
||||
for _, id := range dbIDs {
|
||||
uid, err := ToUUID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if uid != uuid.Nil {
|
||||
ids = append(ids, uid)
|
||||
}
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package database_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestToDBUUID(t *testing.T) {
|
||||
id := uuid.New()
|
||||
|
||||
dbID, err := database.ToDBUUID(id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, dbID.Valid)
|
||||
assert.Equal(t, id.String(), uuid.UUID(dbID.Bytes).String())
|
||||
}
|
||||
|
||||
func TestToDBUUIDNil(t *testing.T) {
|
||||
id := uuid.Nil
|
||||
|
||||
dbID, err := database.ToDBUUID(id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.False(t, dbID.Valid)
|
||||
assert.Equal(t, id.String(), uuid.UUID(dbID.Bytes).String())
|
||||
}
|
||||
|
||||
func TestToDBUUIDArray(t *testing.T) {
|
||||
ids := []uuid.UUID{uuid.Nil, uuid.New()}
|
||||
|
||||
dbIDs, err := database.ToDBUUIDArray(ids)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, dbIDs, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{database.MustToDBUUID(ids[1])}, dbIDs)
|
||||
}
|
||||
|
||||
func TestToUUID(t *testing.T) {
|
||||
dbID, err := database.ToDBUUID(uuid.New())
|
||||
require.NoError(t, err)
|
||||
|
||||
id, err := database.ToUUID(dbID)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, id.String(), uuid.UUID(dbID.Bytes).String())
|
||||
}
|
||||
|
||||
func TestToUUIDArray(t *testing.T) {
|
||||
ogIDs := []uuid.UUID{uuid.Nil, uuid.New()}
|
||||
dbIDs := database.MustToDBUUIDArray(ogIDs)
|
||||
|
||||
ids, err := database.ToUUIDArray(dbIDs)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, ids, 1)
|
||||
assert.ElementsMatch(t, []uuid.UUID{ogIDs[1]}, ids)
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
-- name: HasDocumentCleanEntry :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM currentCleanEntries WHERE documentId = @documentId
|
||||
);
|
||||
|
||||
-- name: GetCleanEntry :one
|
||||
SELECT id, documentId, bucket, key, version, mimetype, fail
|
||||
FROM currentCleanEntries
|
||||
WHERE id = @cleanId;
|
||||
|
||||
-- name: GetCleanEntryByDocId :one
|
||||
SELECT id, documentId, bucket, key, version, mimetype, fail
|
||||
FROM currentCleanEntries
|
||||
WHERE documentId = @documentId;
|
||||
|
||||
-- name: AddDocumentClean :one
|
||||
INSERT INTO documentCleans (documentId, bucket, key, mimetype, fail) VALUES ($1, $2, $3, $4, $5) returning id;
|
||||
|
||||
-- name: AddDocumentCleanEntry :exec
|
||||
INSERT INTO documentCleanEntries (cleanId, version) VALUES ($1, $2);
|
||||
|
||||
-- name: GetMostRecentDocumentCleanEntry :one
|
||||
WITH cleans as (
|
||||
SELECT id, documentId, bucket, key, mimetype, fail
|
||||
FROM documentCleans dc
|
||||
WHERE documentId = @documentId ORDER BY id DESC
|
||||
)
|
||||
SELECT
|
||||
dc.id,
|
||||
dc.documentId,
|
||||
dc.bucket,
|
||||
dc.key,
|
||||
dce.version,
|
||||
dc.mimetype,
|
||||
dc.fail
|
||||
FROM cleans dc
|
||||
JOIN documentCleanEntries dce ON dc.id = dce.cleanId
|
||||
ORDER BY dc.id DESC, dce.id DESC
|
||||
LIMIT 1;
|
||||
@@ -0,0 +1,110 @@
|
||||
-- name: CreateClient :one
|
||||
INSERT INTO clients (externalId, name) VALUES ($1, $2) RETURNING id;
|
||||
|
||||
-- name: GetClient :one
|
||||
SELECT * FROM fullClients WHERE id = $1;
|
||||
|
||||
-- name: GetClientByExternalId :one
|
||||
SELECT * FROM fullClients WHERE externalId = $1;
|
||||
|
||||
-- name: UpdateClient :exec
|
||||
UPDATE clients SET name = $1 WHERE id = $2;
|
||||
|
||||
-- name: AddClientCanSync :exec
|
||||
INSERT INTO clientCanSync (canSync, clientId) VALUES ($1, $2);
|
||||
|
||||
-- name: IsClientSynced :one
|
||||
WITH
|
||||
docs AS (
|
||||
-- Get all documents for this client
|
||||
SELECT id, clientId FROM documents WHERE clientId = $1
|
||||
),
|
||||
doc_clean_entries as (
|
||||
-- Documents with their current clean entries
|
||||
SELECT
|
||||
d.id AS document_id,
|
||||
d.clientId as client_id,
|
||||
cte.id AS clean_entry_id,
|
||||
cte.fail as clean_fail
|
||||
FROM
|
||||
docs d
|
||||
LEFT JOIN currentCleanEntries cte ON cte.documentId = d.id
|
||||
),
|
||||
doc_text_entries AS (
|
||||
-- Documents with their current text entries
|
||||
SELECT
|
||||
d.document_id,
|
||||
cte.id AS text_entry_id,
|
||||
d.clean_entry_id,
|
||||
d.clean_fail
|
||||
FROM
|
||||
doc_clean_entries d
|
||||
LEFT JOIN currentTextEntries cte ON cte.cleanEntryId = d.clean_entry_id
|
||||
),
|
||||
required_results AS (
|
||||
-- All required document-query-version combinations
|
||||
SELECT
|
||||
d.document_id,
|
||||
cqdt.queryId,
|
||||
cqdt.queryVersion,
|
||||
dte.text_entry_id
|
||||
FROM
|
||||
doc_clean_entries d
|
||||
JOIN collectorQueryDependencyTree cqdt ON cqdt.clientId = d.client_id
|
||||
JOIN doc_text_entries dte ON dte.document_id = d.document_id
|
||||
and dte.text_entry_id IS NOT NULL
|
||||
where d.clean_fail is null
|
||||
),
|
||||
existing_results AS (
|
||||
-- Valid results that exist
|
||||
SELECT
|
||||
rr.document_id AS document_id,
|
||||
r.queryId,
|
||||
r.id AS result_id
|
||||
FROM
|
||||
results r
|
||||
JOIN required_results rr ON
|
||||
r.queryId = rr.queryId AND
|
||||
r.queryVersion = rr.queryVersion AND
|
||||
r.textEntryId = rr.text_entry_id
|
||||
),
|
||||
missing_results AS (
|
||||
-- Find missing results
|
||||
SELECT rr.queryId
|
||||
FROM required_results rr
|
||||
LEFT JOIN existing_results er on er.queryId = rr.queryId
|
||||
WHERE er.result_id is null
|
||||
),
|
||||
dependency_check AS (
|
||||
-- Check for missing dependencies
|
||||
SELECT DISTINCT er.queryId, er.result_id, qcri.queryId, rd.resultId
|
||||
FROM existing_results er
|
||||
JOIN queryCurrentRequiredIds qcri on qcri.requiredQueryId = er.queryId
|
||||
LEFT JOIN resultDependencies rd on rd.requiredResultId = er.result_id
|
||||
WHERE rd.resultId is null
|
||||
)
|
||||
SELECT (
|
||||
-- No documents means client is synced
|
||||
NOT EXISTS (SELECT 1 FROM docs)
|
||||
|
||||
OR
|
||||
|
||||
-- Documents with no text entries
|
||||
(
|
||||
NOT EXISTS (
|
||||
SELECT 1 FROM doc_text_entries
|
||||
where clean_entry_id is null or
|
||||
(clean_fail is null and text_entry_id is null)
|
||||
)
|
||||
|
||||
and
|
||||
|
||||
-- Documents with missing results
|
||||
NOT EXISTS (SELECT 1 FROM missing_results)
|
||||
|
||||
and
|
||||
|
||||
-- Documents with missing dependencies
|
||||
NOT EXISTS (SELECT 1 FROM dependency_check)
|
||||
)::bool
|
||||
)::bool as is_synced;
|
||||
@@ -0,0 +1,31 @@
|
||||
-- name: ListCollectorQueries :many
|
||||
SELECT * FROM collectorQueryDependencyTree WHERE clientId = @clientId;
|
||||
|
||||
-- name: GetCollectorByClientID :one
|
||||
SELECT * FROM fullActiveCollectors WHERE clientId = @clientId LIMIT 1;
|
||||
|
||||
-- name: GetCollectorByClientExternalID :one
|
||||
WITH client as (
|
||||
SELECT id from clients where externalId = @clientId
|
||||
)
|
||||
SELECT fc.*
|
||||
FROM fullActiveCollectors as fc
|
||||
JOIN client as c ON fc.clientId = c.id LIMIT 1;
|
||||
|
||||
-- name: AddLatestCollectorVersion :one
|
||||
INSERT INTO collectorVersions (clientId) VALUES ($1) RETURNING id;
|
||||
|
||||
-- name: SetActiveCollectorVersion :exec
|
||||
INSERT INTO collectorActiveVersions (clientId, versionId) VALUES ($1, $2);
|
||||
|
||||
-- name: SetCollectorCleanVersion :exec
|
||||
INSERT INTO collectorMinCleanVersions (clientId, addedVersion, versionId) VALUES ($1, $2, $3);
|
||||
|
||||
-- name: SetCollectorTextVersion :exec
|
||||
INSERT INTO collectorMinTextVersions (clientId, addedVersion, versionId) VALUES ($1, $2, $3);
|
||||
|
||||
-- name: AddCollectorQuery :exec
|
||||
INSERT INTO collectorQueries (clientId, name, queryId, addedVersion) VALUES ($1, $2, $3, $4);
|
||||
|
||||
-- name: RemoveCollectorQuery :exec
|
||||
UPDATE collectorQueries SET removedVersion = $1 WHERE queryId = $2 and clientId = $3 and removedVersion is null;
|
||||
@@ -0,0 +1,52 @@
|
||||
-- name: GetDocumentSummary :one
|
||||
SELECT id, clientId, hash FROM documents WHERE id = $1;
|
||||
|
||||
-- name: GetDocumentExternal :one
|
||||
WITH
|
||||
docs AS (
|
||||
SELECT id, hash, clientId
|
||||
FROM documents
|
||||
WHERE id = @documentId
|
||||
),
|
||||
namedResults AS (
|
||||
SELECT
|
||||
q.name,
|
||||
dd.id,
|
||||
d.value
|
||||
FROM currentCollectorQueries AS q
|
||||
JOIN docs as dd on dd.clientId = q.clientId
|
||||
LEFT JOIN listValidDocumentResults(@documentId) AS d
|
||||
ON d.queryId = q.queryId and q.name is not null
|
||||
)
|
||||
SELECT
|
||||
d.id,
|
||||
c.externalId AS clientId,
|
||||
d.hash,
|
||||
COALESCE(jsonb_object_agg(r.name, r.value) FILTER (WHERE r.name IS NOT NULL), '{}') AS fields
|
||||
FROM docs AS d
|
||||
JOIN clients AS c ON c.id = d.clientId
|
||||
LEFT JOIN namedResults AS r ON d.id = r.id
|
||||
GROUP BY d.id, c.externalId, d.hash;
|
||||
|
||||
-- name: ListDocumentsByClientExternalId :many
|
||||
WITH client as (
|
||||
SELECT id from clients where externalId = @clientId
|
||||
)
|
||||
SELECT d.id, d.hash
|
||||
from documents as d
|
||||
JOIN client as c on d.clientId = c.id;
|
||||
|
||||
-- name: CreateDocument :one
|
||||
INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id;
|
||||
|
||||
-- name: AddDocumentEntry :exec
|
||||
INSERT INTO documentEntries (documentId, bucket, key) VALUES ($1, $2, $3);
|
||||
|
||||
-- name: GetDocumentEntry :one
|
||||
SELECT documentId, bucket, key FROM documentEntries WHERE documentId = $1 ORDER BY id DESC LIMIT 1;
|
||||
|
||||
-- name: GetDocumentIDByHash :one
|
||||
SELECT id FROM documents WHERE hash = $1 and clientId = $2;
|
||||
|
||||
-- name: ListDocumentIDsBatch :many
|
||||
SELECT id, totalCount FROM listDocumentIDs(@clientId, @batchSize, @pageOffset);
|
||||
@@ -0,0 +1,87 @@
|
||||
-- name: GetActiveQueryConfig :one
|
||||
SELECT config FROM queryCurrentConfigs where queryId = $1;
|
||||
|
||||
-- name: GetQuery :one
|
||||
SELECT * FROM fullActiveQueries WHERE id = $1;
|
||||
|
||||
-- name: GetQueryWithVersion :one
|
||||
WITH query as (
|
||||
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 isInVersion(@version, c.addedVersion, c.removedVersion)
|
||||
),
|
||||
requiredIds as (
|
||||
SELECT r.queryId,
|
||||
coalesce(
|
||||
ARRAY_AGG(DISTINCT r.requiredQueryId)
|
||||
FILTER (WHERE r.requiredQueryId != '00000000-0000-0000-0000-000000000000')::uuid[],
|
||||
array[]::uuid[]
|
||||
)::uuid[] as requiredIds
|
||||
FROM query AS q
|
||||
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
and isInVersion(@version, r.addedVersion, r.removedVersion)
|
||||
GROUP BY r.queryId
|
||||
)
|
||||
SELECT DISTINCT q.id, q.type,
|
||||
av.activeVersion,
|
||||
lv.latestVersion, c.config,
|
||||
r.requiredIds
|
||||
FROM query AS q
|
||||
JOIN queryCurrentActiveVersions as av on q.id = av.queryId
|
||||
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;
|
||||
|
||||
-- name: ListQueries :many
|
||||
SELECT * FROM fullActiveQueries;
|
||||
|
||||
-- name: ListQueriesById :many
|
||||
SELECT * FROM fullActiveQueries WHERE id = any($1);
|
||||
|
||||
-- name: CreateQuery :one
|
||||
INSERT INTO queries (type) VALUES ($1) RETURNING id;
|
||||
|
||||
-- name: AddLatestQueryVersion :one
|
||||
INSERT INTO queryVersions (queryId) VALUES ($1) RETURNING id;
|
||||
|
||||
-- name: AddActiveQueryVersion :exec
|
||||
INSERT INTO queryActiveVersions (queryId, versionId) VALUES ($1, $2);
|
||||
|
||||
-- name: AddRequiredQuery :exec
|
||||
INSERT INTO requiredQueries (queryId, requiredQueryId, addedVersion) VALUES ($1, $2, $3);
|
||||
|
||||
-- name: RemoveRequiredQuery :exec
|
||||
UPDATE requiredQueries SET removedVersion = $1 WHERE requiredQueryId = $2 and queryId = $3 and removedVersion is null;
|
||||
|
||||
-- name: SetQueryConfig :exec
|
||||
INSERT INTO queryConfigs (queryId, config, addedVersion) VALUES ($1, $2, $3);
|
||||
|
||||
-- name: AllQueriesExist :one
|
||||
SELECT COUNT(*) = COUNT(DISTINCT id) AS all_exist
|
||||
FROM unnest($1::uuid[]) AS input_id
|
||||
LEFT JOIN queries ON input_id = queries.id;
|
||||
|
||||
-- name: IsQueryInDependencyTree :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1 FROM queryActiveDependencies
|
||||
WHERE id = any(@requiredQueryIds)
|
||||
and requiredQueryId = @queryId
|
||||
or @queryId = any(@requiredQueryIds)
|
||||
);
|
||||
|
||||
-- name: ListQueryDirectDependentsByDocumentID :many
|
||||
WITH doc AS (
|
||||
SELECT id, clientId FROM documents where id = @documentId
|
||||
)
|
||||
SELECT dt.queryId
|
||||
FROM doc as d
|
||||
JOIN collectorQueryDependencyTree as dt
|
||||
on d.clientId = dt.clientId
|
||||
and @queryId = any(dt.requiredIds);
|
||||
|
||||
-- name: ListQueryClientIDs :many
|
||||
SELECT clientId FROM collectorQueryDependencyTree WHERE queryId = $1;
|
||||
@@ -0,0 +1,84 @@
|
||||
-- name: ListQueryRequirementValues :many
|
||||
WITH reqQueries as (
|
||||
SELECT av.queryId, av.activeVersion, q.type
|
||||
FROM requiredQueries as rq
|
||||
JOIN queryCurrentActiveVersions as av on av.queryId = rq.requiredQueryId
|
||||
JOIN queries as q on q.id = av.queryId
|
||||
WHERE rq.queryId = @queryId
|
||||
and isInVersion(@version, rq.addedVersion, rq.removedVersion)
|
||||
),
|
||||
docs as (
|
||||
SELECT id, clientId
|
||||
FROM documents
|
||||
WHERE id = @documentId
|
||||
),
|
||||
codeVersions as (
|
||||
SELECT
|
||||
d.id as documentId,
|
||||
mcv.minCleanVersion,
|
||||
mtv.minTextVersion
|
||||
FROM docs as d
|
||||
JOIN currentCollectorMinTextVersions as mtv on mtv.clientId = d.clientId
|
||||
JOIN currentCollectorMinCleanVersions as mcv on mcv.clientId = d.clientId
|
||||
),
|
||||
latestVersions AS (
|
||||
SELECT
|
||||
r.id,
|
||||
rq.queryId,
|
||||
rq.type,
|
||||
r.queryVersion,
|
||||
r.textEntryId,
|
||||
r.value,
|
||||
ROW_NUMBER() OVER (
|
||||
PARTITION BY r.queryId
|
||||
ORDER BY r.id DESC
|
||||
) as rowNumber
|
||||
FROM reqQueries as rq
|
||||
JOIN currentTextEntries as cte on cte.documentId = @documentId
|
||||
LEFT JOIN results as r ON rq.queryId = r.queryId
|
||||
and r.queryVersion = rq.activeVersion
|
||||
and cte.id = r.textEntryId
|
||||
)
|
||||
SELECT DISTINCT id, queryId, type, value
|
||||
FROM latestVersions
|
||||
WHERE rowNumber = 1;
|
||||
|
||||
-- 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);
|
||||
|
||||
-- name: GetResultValueWithVersion :one
|
||||
WITH doc as (
|
||||
SELECT id, clientId
|
||||
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;
|
||||
|
||||
-- name: ListUnsyncedNoDepsQueriesByDocId :many
|
||||
WITH docs as (
|
||||
SELECT id, clientId from documents where id = $1
|
||||
),
|
||||
unsyncedQueries AS (
|
||||
SELECT DISTINCT dt.queryId, dt.requiredIds
|
||||
from docs as d
|
||||
JOIN collectorQueryDependencyTree as dt on d.clientId = dt.clientId
|
||||
JOIN currentTextEntries as cte on cte.documentId = d.id
|
||||
LEFT JOIN results as r
|
||||
on r.queryId = dt.queryId
|
||||
and r.queryVersion = dt.queryVersion
|
||||
and cte.id = r.textEntryId
|
||||
where r.value is null
|
||||
)
|
||||
SELECT DISTINCT queryId FROM unsyncedQueries as baseuq
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM unsyncedQueries as uq WHERE uq.queryId = any(baseuq.requiredIds)
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
-- name: IsDocumentTextExtracted :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM currentTextEntries WHERE documentId = @documentId
|
||||
);
|
||||
|
||||
-- name: GetDocumentTextExtractionByHash :one
|
||||
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
FROM currentTextEntries
|
||||
WHERE cleanEntryId = @cleanEntryId and hash = @hash;
|
||||
|
||||
-- name: AddDocumentText :one
|
||||
INSERT INTO documentTextExtractions (bucket, key, cleanEntryId, hash) VALUES ($1, $2, $3, $4) returning id;
|
||||
|
||||
-- name: AddDocumentTextEntry :exec
|
||||
INSERT INTO documentTextExtractionEntries (textId, version) VALUES ($1, $2);
|
||||
|
||||
-- name: GetTextEntryByDocId :one
|
||||
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
FROM currentTextEntries
|
||||
WHERE documentId = @documentId;
|
||||
@@ -8,7 +8,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addDocumentClean = `-- name: AddDocumentClean :one
|
||||
@@ -16,7 +16,7 @@ INSERT INTO documentCleans (documentId, bucket, key, mimetype, fail) VALUES ($1,
|
||||
`
|
||||
|
||||
type AddDocumentCleanParams struct {
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket *string `db:"bucket"`
|
||||
Key *string `db:"key"`
|
||||
Mimetype NullCleanmimetype `db:"mimetype"`
|
||||
@@ -26,7 +26,7 @@ type AddDocumentCleanParams struct {
|
||||
// AddDocumentClean
|
||||
//
|
||||
// INSERT INTO documentCleans (documentId, bucket, key, mimetype, fail) VALUES ($1, $2, $3, $4, $5) returning id
|
||||
func (q *Queries) AddDocumentClean(ctx context.Context, arg *AddDocumentCleanParams) (pgtype.UUID, error) {
|
||||
func (q *Queries) AddDocumentClean(ctx context.Context, arg *AddDocumentCleanParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, addDocumentClean,
|
||||
arg.Documentid,
|
||||
arg.Bucket,
|
||||
@@ -34,7 +34,7 @@ func (q *Queries) AddDocumentClean(ctx context.Context, arg *AddDocumentCleanPar
|
||||
arg.Mimetype,
|
||||
arg.Fail,
|
||||
)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
@@ -44,8 +44,8 @@ INSERT INTO documentCleanEntries (cleanId, version) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type AddDocumentCleanEntryParams struct {
|
||||
Cleanid pgtype.UUID `db:"cleanid"`
|
||||
Version int64 `db:"version"`
|
||||
Cleanid uuid.UUID `db:"cleanid"`
|
||||
Version int64 `db:"version"`
|
||||
}
|
||||
|
||||
// AddDocumentCleanEntry
|
||||
@@ -67,7 +67,7 @@ SELECT id, documentId, bucket, key, version, mimetype, fail
|
||||
// SELECT id, documentId, bucket, key, version, mimetype, fail
|
||||
// FROM currentCleanEntries
|
||||
// WHERE id = $1
|
||||
func (q *Queries) GetCleanEntry(ctx context.Context, cleanid pgtype.UUID) (*Currentcleanentry, error) {
|
||||
func (q *Queries) GetCleanEntry(ctx context.Context, cleanid uuid.UUID) (*Currentcleanentry, error) {
|
||||
row := q.db.QueryRow(ctx, getCleanEntry, cleanid)
|
||||
var i Currentcleanentry
|
||||
err := row.Scan(
|
||||
@@ -93,7 +93,7 @@ SELECT id, documentId, bucket, key, version, mimetype, fail
|
||||
// SELECT id, documentId, bucket, key, version, mimetype, fail
|
||||
// FROM currentCleanEntries
|
||||
// WHERE documentId = $1
|
||||
func (q *Queries) GetCleanEntryByDocId(ctx context.Context, documentid pgtype.UUID) (*Currentcleanentry, error) {
|
||||
func (q *Queries) GetCleanEntryByDocId(ctx context.Context, documentid uuid.UUID) (*Currentcleanentry, error) {
|
||||
row := q.db.QueryRow(ctx, getCleanEntryByDocId, documentid)
|
||||
var i Currentcleanentry
|
||||
err := row.Scan(
|
||||
@@ -129,8 +129,8 @@ LIMIT 1
|
||||
`
|
||||
|
||||
type GetMostRecentDocumentCleanEntryRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket *string `db:"bucket"`
|
||||
Key *string `db:"key"`
|
||||
Version int64 `db:"version"`
|
||||
@@ -157,7 +157,7 @@ type GetMostRecentDocumentCleanEntryRow struct {
|
||||
// JOIN documentCleanEntries dce ON dc.id = dce.cleanId
|
||||
// ORDER BY dc.id DESC, dce.id DESC
|
||||
// LIMIT 1
|
||||
func (q *Queries) GetMostRecentDocumentCleanEntry(ctx context.Context, documentid pgtype.UUID) (*GetMostRecentDocumentCleanEntryRow, error) {
|
||||
func (q *Queries) GetMostRecentDocumentCleanEntry(ctx context.Context, documentid uuid.UUID) (*GetMostRecentDocumentCleanEntryRow, error) {
|
||||
row := q.db.QueryRow(ctx, getMostRecentDocumentCleanEntry, documentid)
|
||||
var i GetMostRecentDocumentCleanEntryRow
|
||||
err := row.Scan(
|
||||
@@ -183,7 +183,7 @@ SELECT EXISTS(
|
||||
// SELECT EXISTS(
|
||||
// SELECT 1 FROM currentCleanEntries WHERE documentId = $1
|
||||
// )
|
||||
func (q *Queries) HasDocumentCleanEntry(ctx context.Context, documentid pgtype.UUID) (bool, error) {
|
||||
func (q *Queries) HasDocumentCleanEntry(ctx context.Context, documentid uuid.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, hasDocumentCleanEntry, documentid)
|
||||
var exists bool
|
||||
err := row.Scan(&exists)
|
||||
|
||||
@@ -2,8 +2,6 @@ package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database/repository"
|
||||
@@ -22,7 +20,6 @@ func TestClean(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
|
||||
@@ -8,7 +8,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addClientCanSync = `-- name: AddClientCanSync :exec
|
||||
@@ -16,8 +16,8 @@ INSERT INTO clientCanSync (canSync, clientId) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type AddClientCanSyncParams struct {
|
||||
Cansync bool `db:"cansync"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Cansync bool `db:"cansync"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
}
|
||||
|
||||
// AddClientCanSync
|
||||
@@ -40,9 +40,9 @@ type CreateClientParams struct {
|
||||
// CreateClient
|
||||
//
|
||||
// INSERT INTO clients (externalId, name) VALUES ($1, $2) RETURNING id
|
||||
func (q *Queries) CreateClient(ctx context.Context, arg *CreateClientParams) (pgtype.UUID, error) {
|
||||
func (q *Queries) CreateClient(ctx context.Context, arg *CreateClientParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createClient, arg.Externalid, arg.Name)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
@@ -54,7 +54,7 @@ SELECT id, externalid, name, cansync FROM fullClients WHERE id = $1
|
||||
// GetClient
|
||||
//
|
||||
// SELECT id, externalid, name, cansync FROM fullClients WHERE id = $1
|
||||
func (q *Queries) GetClient(ctx context.Context, id pgtype.UUID) (*Fullclient, error) {
|
||||
func (q *Queries) GetClient(ctx context.Context, id uuid.UUID) (*Fullclient, error) {
|
||||
row := q.db.QueryRow(ctx, getClient, id)
|
||||
var i Fullclient
|
||||
err := row.Scan(
|
||||
@@ -278,7 +278,7 @@ SELECT (
|
||||
// NOT EXISTS (SELECT 1 FROM dependency_check)
|
||||
// )::bool
|
||||
// )::bool as is_synced
|
||||
func (q *Queries) IsClientSynced(ctx context.Context, dollar_1 pgtype.UUID) (bool, error) {
|
||||
func (q *Queries) IsClientSynced(ctx context.Context, dollar_1 *uuid.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, isClientSynced, dollar_1)
|
||||
var is_synced bool
|
||||
err := row.Scan(&is_synced)
|
||||
@@ -290,8 +290,8 @@ UPDATE clients SET name = $1 WHERE id = $2
|
||||
`
|
||||
|
||||
type UpdateClientParams struct {
|
||||
Name string `db:"name"`
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Name string `db:"name"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
}
|
||||
|
||||
// UpdateClient
|
||||
|
||||
@@ -2,8 +2,6 @@ package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database/repository"
|
||||
@@ -22,7 +20,6 @@ func TestClient(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
|
||||
@@ -8,7 +8,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addCollectorQuery = `-- name: AddCollectorQuery :exec
|
||||
@@ -16,10 +16,10 @@ INSERT INTO collectorQueries (clientId, name, queryId, addedVersion) VALUES ($1,
|
||||
`
|
||||
|
||||
type AddCollectorQueryParams struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Name string `db:"name"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Name string `db:"name"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
}
|
||||
|
||||
// AddCollectorQuery
|
||||
@@ -42,7 +42,7 @@ INSERT INTO collectorVersions (clientId) VALUES ($1) RETURNING id
|
||||
// AddLatestCollectorVersion
|
||||
//
|
||||
// INSERT INTO collectorVersions (clientId) VALUES ($1) RETURNING id
|
||||
func (q *Queries) AddLatestCollectorVersion(ctx context.Context, clientid pgtype.UUID) (int32, error) {
|
||||
func (q *Queries) AddLatestCollectorVersion(ctx context.Context, clientid uuid.UUID) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, addLatestCollectorVersion, clientid)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
@@ -87,7 +87,7 @@ SELECT clientid, mincleanversion, mintextversion, activeversion, latestversion,
|
||||
// GetCollectorByClientID
|
||||
//
|
||||
// SELECT clientid, mincleanversion, mintextversion, activeversion, latestversion, fields FROM fullActiveCollectors WHERE clientId = $1 LIMIT 1
|
||||
func (q *Queries) GetCollectorByClientID(ctx context.Context, clientid pgtype.UUID) (*Fullactivecollector, error) {
|
||||
func (q *Queries) GetCollectorByClientID(ctx context.Context, clientid uuid.UUID) (*Fullactivecollector, error) {
|
||||
row := q.db.QueryRow(ctx, getCollectorByClientID, clientid)
|
||||
var i Fullactivecollector
|
||||
err := row.Scan(
|
||||
@@ -108,7 +108,7 @@ SELECT clientid, queryid, type, queryversion, requiredids FROM collectorQueryDep
|
||||
// ListCollectorQueries
|
||||
//
|
||||
// SELECT clientid, queryid, type, queryversion, requiredids FROM collectorQueryDependencyTree WHERE clientId = $1
|
||||
func (q *Queries) ListCollectorQueries(ctx context.Context, clientid pgtype.UUID) ([]*Collectorquerydependencytree, error) {
|
||||
func (q *Queries) ListCollectorQueries(ctx context.Context, clientid uuid.UUID) ([]*Collectorquerydependencytree, error) {
|
||||
rows, err := q.db.Query(ctx, listCollectorQueries, clientid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -139,9 +139,9 @@ UPDATE collectorQueries SET removedVersion = $1 WHERE queryId = $2 and clientId
|
||||
`
|
||||
|
||||
type RemoveCollectorQueryParams struct {
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
}
|
||||
|
||||
// RemoveCollectorQuery
|
||||
@@ -157,8 +157,8 @@ INSERT INTO collectorActiveVersions (clientId, versionId) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type SetActiveCollectorVersionParams struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
}
|
||||
|
||||
// SetActiveCollectorVersion
|
||||
@@ -174,9 +174,9 @@ INSERT INTO collectorMinCleanVersions (clientId, addedVersion, versionId) VALUES
|
||||
`
|
||||
|
||||
type SetCollectorCleanVersionParams struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
}
|
||||
|
||||
// SetCollectorCleanVersion
|
||||
@@ -192,9 +192,9 @@ INSERT INTO collectorMinTextVersions (clientId, addedVersion, versionId) VALUES
|
||||
`
|
||||
|
||||
type SetCollectorTextVersionParams struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
}
|
||||
|
||||
// SetCollectorTextVersion
|
||||
|
||||
@@ -3,16 +3,13 @@ package repository_test
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -25,7 +22,6 @@ func TestCollector(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -124,7 +120,7 @@ func TestCollector(t *testing.T) {
|
||||
Mintextversion: minTextVersion,
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
Fields: []byte(fmt.Sprintf("{\"example_key\": \"%s\"}", database.MustToUUID(jsonId).String())),
|
||||
Fields: []byte(fmt.Sprintf("{\"example_key\": \"%s\"}", jsonId.String())),
|
||||
}, coll)
|
||||
|
||||
err = queries.SetCollectorCleanVersion(ctx, &repository.SetCollectorCleanVersionParams{
|
||||
@@ -142,7 +138,7 @@ func TestCollector(t *testing.T) {
|
||||
Mintextversion: minTextVersion,
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
Fields: []byte(fmt.Sprintf("{\"example_key\": \"%s\"}", database.MustToUUID(jsonId).String())),
|
||||
Fields: []byte(fmt.Sprintf("{\"example_key\": \"%s\"}", jsonId.String())),
|
||||
}, coll)
|
||||
|
||||
qs, err := queries.ListCollectorQueries(ctx, clientId)
|
||||
@@ -151,17 +147,17 @@ func TestCollector(t *testing.T) {
|
||||
assert.ElementsMatch(t, []*repository.Collectorquerydependencytree{
|
||||
{
|
||||
Clientid: clientId,
|
||||
Queryid: jsonId,
|
||||
Queryid: &jsonId,
|
||||
Queryversion: 1,
|
||||
Type: repository.QuerytypeJsonExtractor,
|
||||
Requiredids: []pgtype.UUID{contextId},
|
||||
Requiredids: []uuid.UUID{contextId},
|
||||
},
|
||||
{
|
||||
Clientid: clientId,
|
||||
Queryid: contextId,
|
||||
Queryid: &contextId,
|
||||
Queryversion: 0,
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
},
|
||||
}, qs)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addDocumentEntry = `-- name: AddDocumentEntry :exec
|
||||
@@ -16,9 +16,9 @@ INSERT INTO documentEntries (documentId, bucket, key) VALUES ($1, $2, $3)
|
||||
`
|
||||
|
||||
type AddDocumentEntryParams struct {
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
}
|
||||
|
||||
// AddDocumentEntry
|
||||
@@ -34,16 +34,16 @@ INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
|
||||
`
|
||||
|
||||
type CreateDocumentParams struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
// CreateDocument
|
||||
//
|
||||
// INSERT INTO documents (clientId, hash) VALUES ($1, $2) RETURNING id
|
||||
func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams) (pgtype.UUID, error) {
|
||||
func (q *Queries) CreateDocument(ctx context.Context, arg *CreateDocumentParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createDocument, arg.Clientid, arg.Hash)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
@@ -53,15 +53,15 @@ SELECT documentId, bucket, key FROM documentEntries WHERE documentId = $1 ORDER
|
||||
`
|
||||
|
||||
type GetDocumentEntryRow struct {
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
}
|
||||
|
||||
// GetDocumentEntry
|
||||
//
|
||||
// SELECT documentId, bucket, key FROM documentEntries WHERE documentId = $1 ORDER BY id DESC LIMIT 1
|
||||
func (q *Queries) GetDocumentEntry(ctx context.Context, documentid pgtype.UUID) (*GetDocumentEntryRow, error) {
|
||||
func (q *Queries) GetDocumentEntry(ctx context.Context, documentid uuid.UUID) (*GetDocumentEntryRow, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentEntry, documentid)
|
||||
var i GetDocumentEntryRow
|
||||
err := row.Scan(&i.Documentid, &i.Bucket, &i.Key)
|
||||
@@ -97,10 +97,10 @@ GROUP BY d.id, c.externalId, d.hash
|
||||
`
|
||||
|
||||
type GetDocumentExternalRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Clientid string `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
Fields []byte `db:"fields"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Clientid string `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
Fields []byte `db:"fields"`
|
||||
}
|
||||
|
||||
// GetDocumentExternal
|
||||
@@ -130,7 +130,7 @@ type GetDocumentExternalRow struct {
|
||||
// JOIN clients AS c ON c.id = d.clientId
|
||||
// LEFT JOIN namedResults AS r ON d.id = r.id
|
||||
// GROUP BY d.id, c.externalId, d.hash
|
||||
func (q *Queries) GetDocumentExternal(ctx context.Context, documentid pgtype.UUID) (*GetDocumentExternalRow, error) {
|
||||
func (q *Queries) GetDocumentExternal(ctx context.Context, documentid *uuid.UUID) (*GetDocumentExternalRow, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentExternal, documentid)
|
||||
var i GetDocumentExternalRow
|
||||
err := row.Scan(
|
||||
@@ -147,16 +147,16 @@ SELECT id FROM documents WHERE hash = $1 and clientId = $2
|
||||
`
|
||||
|
||||
type GetDocumentIDByHashParams struct {
|
||||
Hash string `db:"hash"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
}
|
||||
|
||||
// GetDocumentIDByHash
|
||||
//
|
||||
// SELECT id FROM documents WHERE hash = $1 and clientId = $2
|
||||
func (q *Queries) GetDocumentIDByHash(ctx context.Context, arg *GetDocumentIDByHashParams) (pgtype.UUID, error) {
|
||||
func (q *Queries) GetDocumentIDByHash(ctx context.Context, arg *GetDocumentIDByHashParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentIDByHash, arg.Hash, arg.Clientid)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
@@ -168,7 +168,7 @@ SELECT id, clientId, hash FROM documents WHERE id = $1
|
||||
// GetDocumentSummary
|
||||
//
|
||||
// SELECT id, clientId, hash FROM documents WHERE id = $1
|
||||
func (q *Queries) GetDocumentSummary(ctx context.Context, id pgtype.UUID) (*Document, error) {
|
||||
func (q *Queries) GetDocumentSummary(ctx context.Context, id uuid.UUID) (*Document, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentSummary, id)
|
||||
var i Document
|
||||
err := row.Scan(&i.ID, &i.Clientid, &i.Hash)
|
||||
@@ -180,14 +180,14 @@ SELECT id, totalCount FROM listDocumentIDs($1, $2, $3)
|
||||
`
|
||||
|
||||
type ListDocumentIDsBatchParams struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Batchsize int32 `db:"batchsize"`
|
||||
Pageoffset int32 `db:"pageoffset"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Batchsize int32 `db:"batchsize"`
|
||||
Pageoffset int32 `db:"pageoffset"`
|
||||
}
|
||||
|
||||
type ListDocumentIDsBatchRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Totalcount *int64 `db:"totalcount"`
|
||||
ID *uuid.UUID `db:"id"`
|
||||
Totalcount *int64 `db:"totalcount"`
|
||||
}
|
||||
|
||||
// ListDocumentIDsBatch
|
||||
@@ -223,8 +223,8 @@ SELECT d.id, d.hash
|
||||
`
|
||||
|
||||
type ListDocumentsByClientExternalIdRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Hash string `db:"hash"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
// ListDocumentsByClientExternalId
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestDocument(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProviderWithBasePath(t, cfg, "../../..")
|
||||
test.SetCfgProvider(t, cfg)
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -126,7 +126,7 @@ func TestDocument(t *testing.T) {
|
||||
Hash: hash,
|
||||
}, doc)
|
||||
|
||||
docext, err := queries.GetDocumentExternal(ctx, id)
|
||||
docext, err := queries.GetDocumentExternal(ctx, &id)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: id,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
@@ -179,75 +180,75 @@ func (e Querytype) Valid() bool {
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Externalid string `db:"externalid"`
|
||||
Name string `db:"name"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Externalid string `db:"externalid"`
|
||||
Name string `db:"name"`
|
||||
}
|
||||
|
||||
type Clientcansync struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Cansync bool `db:"cansync"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Cansync bool `db:"cansync"`
|
||||
}
|
||||
|
||||
type Collectoractiveversion struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
}
|
||||
|
||||
type Collectorcurrentactiveversion struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
}
|
||||
|
||||
type Collectorlatestversion struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
}
|
||||
|
||||
type Collectormincleanversion struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
}
|
||||
|
||||
type Collectormintextversion struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Versionid int64 `db:"versionid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
}
|
||||
|
||||
type Collectorquery struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Name string `db:"name"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Name string `db:"name"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
}
|
||||
|
||||
type Collectorquerydependencytree struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Type Querytype `db:"type"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
Requiredids []pgtype.UUID `db:"requiredids"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Queryid *uuid.UUID `db:"queryid"`
|
||||
Type Querytype `db:"type"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
Requiredids []uuid.UUID `db:"requiredids"`
|
||||
}
|
||||
|
||||
type Collectorversion struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
ID int32 `db:"id"`
|
||||
Addedat pgtype.Timestamp `db:"addedat"`
|
||||
}
|
||||
|
||||
type Currentcleanentry struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket *string `db:"bucket"`
|
||||
Key *string `db:"key"`
|
||||
Version int64 `db:"version"`
|
||||
@@ -256,49 +257,50 @@ type Currentcleanentry struct {
|
||||
}
|
||||
|
||||
type Currentclientcansync struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Cansync bool `db:"cansync"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Cansync bool `db:"cansync"`
|
||||
}
|
||||
|
||||
type Currentcollectormincleanversion struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Mincleanversion int64 `db:"mincleanversion"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Mincleanversion int64 `db:"mincleanversion"`
|
||||
}
|
||||
|
||||
type Currentcollectormintextversion struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Mintextversion int64 `db:"mintextversion"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Mintextversion int64 `db:"mintextversion"`
|
||||
}
|
||||
|
||||
type Currentcollectorqueriesjsonagg struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Fields []byte `db:"fields"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Fields []byte `db:"fields"`
|
||||
}
|
||||
|
||||
type Currentcollectorquery struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Name *string `db:"name"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Name *string `db:"name"`
|
||||
Queryid *uuid.UUID `db:"queryid"`
|
||||
}
|
||||
|
||||
type Currenttextentry struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Version int64 `db:"version"`
|
||||
Cleanentryid pgtype.UUID `db:"cleanentryid"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Version int64 `db:"version"`
|
||||
Hash string `db:"hash"`
|
||||
Cleanentryid uuid.UUID `db:"cleanentryid"`
|
||||
}
|
||||
|
||||
type Document struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
type Documentclean struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket *string `db:"bucket"`
|
||||
Key *string `db:"key"`
|
||||
Mimetype NullCleanmimetype `db:"mimetype"`
|
||||
@@ -306,123 +308,129 @@ type Documentclean struct {
|
||||
}
|
||||
|
||||
type Documentcleanentry struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Cleanid pgtype.UUID `db:"cleanid"`
|
||||
Version int64 `db:"version"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Cleanid uuid.UUID `db:"cleanid"`
|
||||
Version int64 `db:"version"`
|
||||
}
|
||||
|
||||
type Documententry struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
}
|
||||
|
||||
type Documenttextextraction struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Cleanentryid pgtype.UUID `db:"cleanentryid"`
|
||||
Version int64 `db:"version"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Cleanentryid uuid.UUID `db:"cleanentryid"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
type Documenttextextractionentry struct {
|
||||
ID uuid.UUID `db:"id"`
|
||||
Textid uuid.UUID `db:"textid"`
|
||||
Version int64 `db:"version"`
|
||||
}
|
||||
|
||||
type Fullactivecollector struct {
|
||||
Clientid pgtype.UUID `db:"clientid"`
|
||||
Mincleanversion int64 `db:"mincleanversion"`
|
||||
Mintextversion int64 `db:"mintextversion"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Fields []byte `db:"fields"`
|
||||
Clientid uuid.UUID `db:"clientid"`
|
||||
Mincleanversion int64 `db:"mincleanversion"`
|
||||
Mintextversion int64 `db:"mintextversion"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Fields []byte `db:"fields"`
|
||||
}
|
||||
|
||||
type Fullactivequery struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Type Querytype `db:"type"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Config []byte `db:"config"`
|
||||
Requiredids []pgtype.UUID `db:"requiredids"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Type Querytype `db:"type"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Config []byte `db:"config"`
|
||||
Requiredids []uuid.UUID `db:"requiredids"`
|
||||
}
|
||||
|
||||
type Fullclient struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Externalid string `db:"externalid"`
|
||||
Name string `db:"name"`
|
||||
Cansync bool `db:"cansync"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Externalid string `db:"externalid"`
|
||||
Name string `db:"name"`
|
||||
Cansync bool `db:"cansync"`
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Type Querytype `db:"type"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Type Querytype `db:"type"`
|
||||
}
|
||||
|
||||
type Queryactivedependency struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Requiredqueryid *uuid.UUID `db:"requiredqueryid"`
|
||||
}
|
||||
|
||||
type Queryactiveversion struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
}
|
||||
|
||||
type Queryconfig struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Config []byte `db:"config"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Config []byte `db:"config"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
}
|
||||
|
||||
type Querycurrentactiveversion struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
}
|
||||
|
||||
type Querycurrentconfig struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Config []byte `db:"config"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Config []byte `db:"config"`
|
||||
}
|
||||
|
||||
type Querycurrentrequiredid struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Requiredqueryid *uuid.UUID `db:"requiredqueryid"`
|
||||
}
|
||||
|
||||
type Querycurrentrequiredidsagg struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Requiredids []pgtype.UUID `db:"requiredids"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Requiredids []uuid.UUID `db:"requiredids"`
|
||||
}
|
||||
|
||||
type Querylatestversion struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
}
|
||||
|
||||
type Queryversion struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
ID int32 `db:"id"`
|
||||
Addedat pgtype.Timestamp `db:"addedat"`
|
||||
}
|
||||
|
||||
type Requiredquery struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Requiredqueryid uuid.UUID `db:"requiredqueryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Textentryid pgtype.UUID `db:"textentryid"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Value string `db:"value"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Textentryid uuid.UUID `db:"textentryid"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Value string `db:"value"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
}
|
||||
|
||||
type Resultdependency struct {
|
||||
Resultid pgtype.UUID `db:"resultid"`
|
||||
Requiredresultid pgtype.UUID `db:"requiredresultid"`
|
||||
Resultid uuid.UUID `db:"resultid"`
|
||||
Requiredresultid uuid.UUID `db:"requiredresultid"`
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addActiveQueryVersion = `-- name: AddActiveQueryVersion :exec
|
||||
@@ -16,8 +16,8 @@ INSERT INTO queryActiveVersions (queryId, versionId) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type AddActiveQueryVersionParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Versionid int32 `db:"versionid"`
|
||||
}
|
||||
|
||||
// AddActiveQueryVersion
|
||||
@@ -35,7 +35,7 @@ INSERT INTO queryVersions (queryId) VALUES ($1) RETURNING id
|
||||
// AddLatestQueryVersion
|
||||
//
|
||||
// INSERT INTO queryVersions (queryId) VALUES ($1) RETURNING id
|
||||
func (q *Queries) AddLatestQueryVersion(ctx context.Context, queryid pgtype.UUID) (int32, error) {
|
||||
func (q *Queries) AddLatestQueryVersion(ctx context.Context, queryid uuid.UUID) (int32, error) {
|
||||
row := q.db.QueryRow(ctx, addLatestQueryVersion, queryid)
|
||||
var id int32
|
||||
err := row.Scan(&id)
|
||||
@@ -47,9 +47,9 @@ INSERT INTO requiredQueries (queryId, requiredQueryId, addedVersion) VALUES ($1,
|
||||
`
|
||||
|
||||
type AddRequiredQueryParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Requiredqueryid uuid.UUID `db:"requiredqueryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
}
|
||||
|
||||
// AddRequiredQuery
|
||||
@@ -71,7 +71,7 @@ SELECT COUNT(*) = COUNT(DISTINCT id) AS all_exist
|
||||
// SELECT COUNT(*) = COUNT(DISTINCT id) AS all_exist
|
||||
// FROM unnest($1::uuid[]) AS input_id
|
||||
// LEFT JOIN queries ON input_id = queries.id
|
||||
func (q *Queries) AllQueriesExist(ctx context.Context, dollar_1 []pgtype.UUID) (bool, error) {
|
||||
func (q *Queries) AllQueriesExist(ctx context.Context, dollar_1 []uuid.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, allQueriesExist, dollar_1)
|
||||
var all_exist bool
|
||||
err := row.Scan(&all_exist)
|
||||
@@ -85,9 +85,9 @@ INSERT INTO queries (type) VALUES ($1) RETURNING id
|
||||
// CreateQuery
|
||||
//
|
||||
// INSERT INTO queries (type) VALUES ($1) RETURNING id
|
||||
func (q *Queries) CreateQuery(ctx context.Context, type_ Querytype) (pgtype.UUID, error) {
|
||||
func (q *Queries) CreateQuery(ctx context.Context, type_ Querytype) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createQuery, type_)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
@@ -99,7 +99,7 @@ SELECT config FROM queryCurrentConfigs where queryId = $1
|
||||
// GetActiveQueryConfig
|
||||
//
|
||||
// SELECT config FROM queryCurrentConfigs where queryId = $1
|
||||
func (q *Queries) GetActiveQueryConfig(ctx context.Context, queryid pgtype.UUID) ([]byte, error) {
|
||||
func (q *Queries) GetActiveQueryConfig(ctx context.Context, queryid uuid.UUID) ([]byte, error) {
|
||||
row := q.db.QueryRow(ctx, getActiveQueryConfig, queryid)
|
||||
var config []byte
|
||||
err := row.Scan(&config)
|
||||
@@ -113,7 +113,7 @@ SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActi
|
||||
// GetQuery
|
||||
//
|
||||
// SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries WHERE id = $1
|
||||
func (q *Queries) GetQuery(ctx context.Context, id pgtype.UUID) (*Fullactivequery, error) {
|
||||
func (q *Queries) GetQuery(ctx context.Context, id uuid.UUID) (*Fullactivequery, error) {
|
||||
row := q.db.QueryRow(ctx, getQuery, id)
|
||||
var i Fullactivequery
|
||||
err := row.Scan(
|
||||
@@ -161,17 +161,17 @@ SELECT DISTINCT q.id, q.type,
|
||||
`
|
||||
|
||||
type GetQueryWithVersionParams struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Version *int32 `db:"version"`
|
||||
ID *uuid.UUID `db:"id"`
|
||||
Version *int32 `db:"version"`
|
||||
}
|
||||
|
||||
type GetQueryWithVersionRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Type Querytype `db:"type"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Config []byte `db:"config"`
|
||||
Requiredids []pgtype.UUID `db:"requiredids"`
|
||||
ID uuid.UUID `db:"id"`
|
||||
Type Querytype `db:"type"`
|
||||
Activeversion int32 `db:"activeversion"`
|
||||
Latestversion int32 `db:"latestversion"`
|
||||
Config []byte `db:"config"`
|
||||
Requiredids []uuid.UUID `db:"requiredids"`
|
||||
}
|
||||
|
||||
// GetQueryWithVersion
|
||||
@@ -230,8 +230,8 @@ SELECT EXISTS (
|
||||
`
|
||||
|
||||
type IsQueryInDependencyTreeParams struct {
|
||||
Requiredqueryids []pgtype.UUID `db:"requiredqueryids"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Requiredqueryids []uuid.UUID `db:"requiredqueryids"`
|
||||
Queryid *uuid.UUID `db:"queryid"`
|
||||
}
|
||||
|
||||
// IsQueryInDependencyTree
|
||||
@@ -290,7 +290,7 @@ SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActi
|
||||
// ListQueriesById
|
||||
//
|
||||
// SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries WHERE id = any($1)
|
||||
func (q *Queries) ListQueriesById(ctx context.Context, id []pgtype.UUID) ([]*Fullactivequery, error) {
|
||||
func (q *Queries) ListQueriesById(ctx context.Context, id []uuid.UUID) ([]*Fullactivequery, error) {
|
||||
rows, err := q.db.Query(ctx, listQueriesById, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -324,15 +324,15 @@ SELECT clientId FROM collectorQueryDependencyTree WHERE queryId = $1
|
||||
// ListQueryClientIDs
|
||||
//
|
||||
// SELECT clientId FROM collectorQueryDependencyTree WHERE queryId = $1
|
||||
func (q *Queries) ListQueryClientIDs(ctx context.Context, queryid pgtype.UUID) ([]pgtype.UUID, error) {
|
||||
func (q *Queries) ListQueryClientIDs(ctx context.Context, queryid *uuid.UUID) ([]uuid.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, listQueryClientIDs, queryid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []pgtype.UUID{}
|
||||
items := []uuid.UUID{}
|
||||
for rows.Next() {
|
||||
var clientid pgtype.UUID
|
||||
var clientid uuid.UUID
|
||||
if err := rows.Scan(&clientid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -356,8 +356,8 @@ SELECT dt.queryId
|
||||
`
|
||||
|
||||
type ListQueryDirectDependentsByDocumentIDParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Documentid uuid.UUID `db:"documentid"`
|
||||
}
|
||||
|
||||
// ListQueryDirectDependentsByDocumentID
|
||||
@@ -370,15 +370,15 @@ type ListQueryDirectDependentsByDocumentIDParams struct {
|
||||
// JOIN collectorQueryDependencyTree as dt
|
||||
// on d.clientId = dt.clientId
|
||||
// and $1 = any(dt.requiredIds)
|
||||
func (q *Queries) ListQueryDirectDependentsByDocumentID(ctx context.Context, arg *ListQueryDirectDependentsByDocumentIDParams) ([]pgtype.UUID, error) {
|
||||
func (q *Queries) ListQueryDirectDependentsByDocumentID(ctx context.Context, arg *ListQueryDirectDependentsByDocumentIDParams) ([]*uuid.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, listQueryDirectDependentsByDocumentID, arg.Queryid, arg.Documentid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []pgtype.UUID{}
|
||||
items := []*uuid.UUID{}
|
||||
for rows.Next() {
|
||||
var queryid pgtype.UUID
|
||||
var queryid *uuid.UUID
|
||||
if err := rows.Scan(&queryid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -395,9 +395,9 @@ UPDATE requiredQueries SET removedVersion = $1 WHERE requiredQueryId = $2 and qu
|
||||
`
|
||||
|
||||
type RemoveRequiredQueryParams struct {
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
Requiredqueryid pgtype.UUID `db:"requiredqueryid"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Removedversion *int32 `db:"removedversion"`
|
||||
Requiredqueryid uuid.UUID `db:"requiredqueryid"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
}
|
||||
|
||||
// RemoveRequiredQuery
|
||||
@@ -413,9 +413,9 @@ INSERT INTO queryConfigs (queryId, config, addedVersion) VALUES ($1, $2, $3)
|
||||
`
|
||||
|
||||
type SetQueryConfigParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Config []byte `db:"config"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Config []byte `db:"config"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
}
|
||||
|
||||
// SetQueryConfig
|
||||
|
||||
@@ -2,17 +2,13 @@ package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -25,7 +21,6 @@ func TestQueries(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -36,7 +31,6 @@ func TestQueries(t *testing.T) {
|
||||
|
||||
contextQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeContextFull))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, contextQueryID.Valid)
|
||||
|
||||
contextQuery, err := queries.GetQuery(ctx, contextQueryID)
|
||||
require.NoError(t, err)
|
||||
@@ -46,7 +40,7 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 0,
|
||||
Latestversion: 0,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
}, contextQuery)
|
||||
|
||||
ctxVersion, err := queries.AddLatestQueryVersion(ctx, contextQueryID)
|
||||
@@ -61,12 +55,11 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 0,
|
||||
Latestversion: 1,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
}, contextQuery)
|
||||
|
||||
jsonQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeJsonExtractor))
|
||||
require.NoError(t, err)
|
||||
assert.True(t, jsonQueryID.Valid)
|
||||
|
||||
jsonQuery, err := queries.GetQuery(ctx, jsonQueryID)
|
||||
require.NoError(t, err)
|
||||
@@ -76,7 +69,7 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 0,
|
||||
Latestversion: 0,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
}, jsonQuery)
|
||||
|
||||
jsonVersion, err := queries.AddLatestQueryVersion(ctx, jsonQueryID)
|
||||
@@ -91,7 +84,7 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 0,
|
||||
Latestversion: 1,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
}, jsonQuery)
|
||||
|
||||
err = queries.AddActiveQueryVersion(ctx, &repository.AddActiveQueryVersionParams{
|
||||
@@ -108,7 +101,7 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
}, jsonQuery)
|
||||
|
||||
jsonConfig := []byte("{\"path\": \"example_path\"}")
|
||||
@@ -128,7 +121,7 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 1,
|
||||
Latestversion: 1,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{contextQueryID},
|
||||
Requiredids: []uuid.UUID{contextQueryID},
|
||||
}, jsonQuery)
|
||||
|
||||
jsonVersion, err = queries.AddLatestQueryVersion(ctx, jsonQueryID)
|
||||
@@ -143,7 +136,7 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 1,
|
||||
Latestversion: 2,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{contextQueryID},
|
||||
Requiredids: []uuid.UUID{contextQueryID},
|
||||
}, jsonQuery)
|
||||
|
||||
removeV := int32(2)
|
||||
@@ -194,12 +187,12 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 2,
|
||||
Latestversion: 2,
|
||||
Config: jsonQueryConfig,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
}, jsonQuery)
|
||||
|
||||
v := int32(1)
|
||||
versionedQuery, err := queries.GetQueryWithVersion(ctx, &repository.GetQueryWithVersionParams{
|
||||
ID: jsonQueryID,
|
||||
ID: &jsonQueryID,
|
||||
Version: &v,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -209,26 +202,26 @@ func TestQueries(t *testing.T) {
|
||||
Activeversion: 2,
|
||||
Latestversion: 2,
|
||||
Config: jsonConfig,
|
||||
Requiredids: []pgtype.UUID{contextQueryID},
|
||||
Requiredids: []uuid.UUID{contextQueryID},
|
||||
}, versionedQuery)
|
||||
|
||||
all_exist, err := queries.AllQueriesExist(ctx, []pgtype.UUID{})
|
||||
all_exist, err := queries.AllQueriesExist(ctx, []uuid.UUID{})
|
||||
require.NoError(t, err)
|
||||
assert.True(t, all_exist)
|
||||
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []pgtype.UUID{database.MustToDBUUID(uuid.New())})
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []uuid.UUID{uuid.New()})
|
||||
require.NoError(t, err)
|
||||
assert.False(t, all_exist)
|
||||
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []pgtype.UUID{jsonQueryID})
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []uuid.UUID{jsonQueryID})
|
||||
require.NoError(t, err)
|
||||
assert.True(t, all_exist)
|
||||
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []pgtype.UUID{jsonQueryID, contextQueryID})
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []uuid.UUID{jsonQueryID, contextQueryID})
|
||||
require.NoError(t, err)
|
||||
assert.True(t, all_exist)
|
||||
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []pgtype.UUID{jsonQueryID, database.MustToDBUUID(uuid.New())})
|
||||
all_exist, err = queries.AllQueriesExist(ctx, []uuid.UUID{jsonQueryID, uuid.New()})
|
||||
require.NoError(t, err)
|
||||
assert.False(t, all_exist)
|
||||
}
|
||||
@@ -241,7 +234,6 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -283,7 +275,7 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
Queryid: contextQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []uuid.UUID{}, dependents)
|
||||
|
||||
jsonQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeJsonExtractor))
|
||||
require.NoError(t, err)
|
||||
@@ -300,7 +292,7 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
Queryid: jsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []uuid.UUID{}, dependents)
|
||||
|
||||
err = queries.AddRequiredQuery(ctx, &repository.AddRequiredQueryParams{
|
||||
Queryid: jsonQueryID,
|
||||
@@ -314,13 +306,13 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
Queryid: jsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []uuid.UUID{}, dependents)
|
||||
dependents, err = queries.ListQueryDirectDependentsByDocumentID(ctx, &repository.ListQueryDirectDependentsByDocumentIDParams{
|
||||
Documentid: docID,
|
||||
Queryid: contextQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []uuid.UUID{}, dependents)
|
||||
|
||||
err = queries.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{
|
||||
Clientid: clientID,
|
||||
@@ -335,13 +327,13 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
Queryid: jsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{}, dependents)
|
||||
dependents, err = queries.ListQueryDirectDependentsByDocumentID(ctx, &repository.ListQueryDirectDependentsByDocumentIDParams{
|
||||
Documentid: docID,
|
||||
Queryid: contextQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, dependents)
|
||||
|
||||
secondJsonQueryID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeJsonExtractor))
|
||||
require.NoError(t, err)
|
||||
@@ -358,13 +350,13 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
Queryid: jsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{}, dependents)
|
||||
dependents, err = queries.ListQueryDirectDependentsByDocumentID(ctx, &repository.ListQueryDirectDependentsByDocumentIDParams{
|
||||
Documentid: docID,
|
||||
Queryid: contextQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, dependents)
|
||||
|
||||
err = queries.AddRequiredQuery(ctx, &repository.AddRequiredQueryParams{
|
||||
Queryid: secondJsonQueryID,
|
||||
@@ -378,19 +370,19 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
Queryid: secondJsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{}, dependents)
|
||||
dependents, err = queries.ListQueryDirectDependentsByDocumentID(ctx, &repository.ListQueryDirectDependentsByDocumentIDParams{
|
||||
Documentid: docID,
|
||||
Queryid: jsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{}, dependents)
|
||||
dependents, err = queries.ListQueryDirectDependentsByDocumentID(ctx, &repository.ListQueryDirectDependentsByDocumentIDParams{
|
||||
Documentid: docID,
|
||||
Queryid: contextQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, dependents)
|
||||
|
||||
err = queries.AddCollectorQuery(ctx, &repository.AddCollectorQueryParams{
|
||||
Clientid: clientID,
|
||||
@@ -405,51 +397,51 @@ func TestQueryDependencyTree(t *testing.T) {
|
||||
Queryid: secondJsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{}, dependents)
|
||||
dependents, err = queries.ListQueryDirectDependentsByDocumentID(ctx, &repository.ListQueryDirectDependentsByDocumentIDParams{
|
||||
Documentid: docID,
|
||||
Queryid: jsonQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{secondJsonQueryID}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&secondJsonQueryID}, dependents)
|
||||
dependents, err = queries.ListQueryDirectDependentsByDocumentID(ctx, &repository.ListQueryDirectDependentsByDocumentIDParams{
|
||||
Documentid: docID,
|
||||
Queryid: contextQueryID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, dependents)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, dependents)
|
||||
|
||||
isdependent, err := queries.IsQueryInDependencyTree(ctx, &repository.IsQueryInDependencyTreeParams{
|
||||
Queryid: jsonQueryID,
|
||||
Requiredqueryids: []pgtype.UUID{contextQueryID},
|
||||
Queryid: &jsonQueryID,
|
||||
Requiredqueryids: []uuid.UUID{contextQueryID},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isdependent)
|
||||
|
||||
isdependent, err = queries.IsQueryInDependencyTree(ctx, &repository.IsQueryInDependencyTreeParams{
|
||||
Queryid: jsonQueryID,
|
||||
Requiredqueryids: []pgtype.UUID{secondJsonQueryID},
|
||||
Queryid: &jsonQueryID,
|
||||
Requiredqueryids: []uuid.UUID{secondJsonQueryID},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isdependent)
|
||||
|
||||
isdependent, err = queries.IsQueryInDependencyTree(ctx, &repository.IsQueryInDependencyTreeParams{
|
||||
Queryid: jsonQueryID,
|
||||
Requiredqueryids: []pgtype.UUID{jsonQueryID},
|
||||
Queryid: &jsonQueryID,
|
||||
Requiredqueryids: []uuid.UUID{jsonQueryID},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isdependent)
|
||||
|
||||
isdependent, err = queries.IsQueryInDependencyTree(ctx, &repository.IsQueryInDependencyTreeParams{
|
||||
Queryid: secondJsonQueryID,
|
||||
Requiredqueryids: []pgtype.UUID{jsonQueryID, contextQueryID},
|
||||
Queryid: &secondJsonQueryID,
|
||||
Requiredqueryids: []uuid.UUID{jsonQueryID, contextQueryID},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isdependent)
|
||||
|
||||
isdependent, err = queries.IsQueryInDependencyTree(ctx, &repository.IsQueryInDependencyTreeParams{
|
||||
Queryid: contextQueryID,
|
||||
Requiredqueryids: []pgtype.UUID{jsonQueryID, secondJsonQueryID},
|
||||
Queryid: &contextQueryID,
|
||||
Requiredqueryids: []uuid.UUID{jsonQueryID, secondJsonQueryID},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isdependent)
|
||||
@@ -463,7 +455,6 @@ func TestQueriesList(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -488,7 +479,7 @@ func TestQueriesList(t *testing.T) {
|
||||
Activeversion: 0,
|
||||
Latestversion: 0,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
},
|
||||
{
|
||||
ID: contextQueryID,
|
||||
@@ -496,11 +487,11 @@ func TestQueriesList(t *testing.T) {
|
||||
Activeversion: 0,
|
||||
Latestversion: 0,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
},
|
||||
}, qs)
|
||||
|
||||
qs, err = queries.ListQueriesById(ctx, []pgtype.UUID{jsonQueryID})
|
||||
qs, err = queries.ListQueriesById(ctx, []uuid.UUID{jsonQueryID})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 1)
|
||||
assert.ElementsMatch(t, []*repository.Fullactivequery{
|
||||
@@ -510,7 +501,7 @@ func TestQueriesList(t *testing.T) {
|
||||
Activeversion: 0,
|
||||
Latestversion: 0,
|
||||
Config: nil,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
},
|
||||
}, qs)
|
||||
}
|
||||
@@ -523,7 +514,6 @@ func TestListQueryClients(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -535,9 +525,9 @@ func TestListQueryClients(t *testing.T) {
|
||||
contextID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeContextFull))
|
||||
require.NoError(t, err)
|
||||
|
||||
clients, err := queries.ListQueryClientIDs(ctx, contextID)
|
||||
clients, err := queries.ListQueryClientIDs(ctx, &contextID)
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{}, clients)
|
||||
assert.ElementsMatch(t, []uuid.UUID{}, clients)
|
||||
|
||||
clientOneID, err := queries.CreateClient(ctx, &repository.CreateClientParams{
|
||||
Name: "example_client",
|
||||
@@ -559,9 +549,9 @@ func TestListQueryClients(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
clients, err = queries.ListQueryClientIDs(ctx, contextID)
|
||||
clients, err = queries.ListQueryClientIDs(ctx, &contextID)
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{clientOneID}, clients)
|
||||
assert.ElementsMatch(t, []uuid.UUID{clientOneID}, clients)
|
||||
|
||||
clientTwoID, err := queries.CreateClient(ctx, &repository.CreateClientParams{
|
||||
Name: "example_client_dos",
|
||||
@@ -583,9 +573,9 @@ func TestListQueryClients(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
clients, err = queries.ListQueryClientIDs(ctx, contextID)
|
||||
clients, err = queries.ListQueryClientIDs(ctx, &contextID)
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{clientOneID, clientTwoID}, clients)
|
||||
assert.ElementsMatch(t, []uuid.UUID{clientOneID, clientTwoID}, clients)
|
||||
|
||||
jsonID, err := queries.CreateQuery(ctx, repository.Querytype(repository.QuerytypeJsonExtractor))
|
||||
require.NoError(t, err)
|
||||
@@ -605,7 +595,7 @@ func TestListQueryClients(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
clients, err = queries.ListQueryClientIDs(ctx, jsonID)
|
||||
clients, err = queries.ListQueryClientIDs(ctx, &jsonID)
|
||||
require.NoError(t, err)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{clientOneID}, clients)
|
||||
assert.ElementsMatch(t, []uuid.UUID{clientOneID}, clients)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addResult = `-- name: AddResult :one
|
||||
@@ -16,23 +16,23 @@ INSERT INTO results (queryId, value, textEntryId, queryVersion) VALUES ($1, $2,
|
||||
`
|
||||
|
||||
type AddResultParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Value string `db:"value"`
|
||||
Textentryid pgtype.UUID `db:"textentryid"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Value string `db:"value"`
|
||||
Textentryid uuid.UUID `db:"textentryid"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
}
|
||||
|
||||
// AddResult
|
||||
//
|
||||
// INSERT INTO results (queryId, value, textEntryId, queryVersion) VALUES ($1, $2, $3, $4) returning id
|
||||
func (q *Queries) AddResult(ctx context.Context, arg *AddResultParams) (pgtype.UUID, error) {
|
||||
func (q *Queries) AddResult(ctx context.Context, arg *AddResultParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, addResult,
|
||||
arg.Queryid,
|
||||
arg.Value,
|
||||
arg.Textentryid,
|
||||
arg.Queryversion,
|
||||
)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
@@ -42,8 +42,8 @@ INSERT INTO resultDependencies (resultId, requiredResultId) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type AddResultDependencyParams struct {
|
||||
Resultid pgtype.UUID `db:"resultid"`
|
||||
Requiredresultid pgtype.UUID `db:"requiredresultid"`
|
||||
Resultid uuid.UUID `db:"resultid"`
|
||||
Requiredresultid uuid.UUID `db:"requiredresultid"`
|
||||
}
|
||||
|
||||
// AddResultDependency
|
||||
@@ -70,14 +70,14 @@ SELECT r.id, r.value
|
||||
`
|
||||
|
||||
type GetResultValueWithVersionParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Queryversion *int32 `db:"queryversion"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Queryid *uuid.UUID `db:"queryid"`
|
||||
Queryversion *int32 `db:"queryversion"`
|
||||
Documentid *uuid.UUID `db:"documentid"`
|
||||
}
|
||||
|
||||
type GetResultValueWithVersionRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Value *string `db:"value"`
|
||||
ID *uuid.UUID `db:"id"`
|
||||
Value *string `db:"value"`
|
||||
}
|
||||
|
||||
// GetResultValueWithVersion
|
||||
@@ -148,16 +148,16 @@ WHERE rowNumber = 1
|
||||
`
|
||||
|
||||
type ListQueryRequirementValuesParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Version *int32 `db:"version"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Queryid *uuid.UUID `db:"queryid"`
|
||||
Version *int32 `db:"version"`
|
||||
Documentid *uuid.UUID `db:"documentid"`
|
||||
}
|
||||
|
||||
type ListQueryRequirementValuesRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Type Querytype `db:"type"`
|
||||
Value *string `db:"value"`
|
||||
ID *uuid.UUID `db:"id"`
|
||||
Queryid uuid.UUID `db:"queryid"`
|
||||
Type Querytype `db:"type"`
|
||||
Value *string `db:"value"`
|
||||
}
|
||||
|
||||
// ListQueryRequirementValues
|
||||
@@ -271,15 +271,15 @@ SELECT DISTINCT queryId FROM unsyncedQueries as baseuq
|
||||
// WHERE NOT EXISTS (
|
||||
// SELECT 1 FROM unsyncedQueries as uq WHERE uq.queryId = any(baseuq.requiredIds)
|
||||
// )
|
||||
func (q *Queries) ListUnsyncedNoDepsQueriesByDocId(ctx context.Context, dollar_1 pgtype.UUID) ([]pgtype.UUID, error) {
|
||||
func (q *Queries) ListUnsyncedNoDepsQueriesByDocId(ctx context.Context, dollar_1 *uuid.UUID) ([]*uuid.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, listUnsyncedNoDepsQueriesByDocId, dollar_1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []pgtype.UUID{}
|
||||
items := []*uuid.UUID{}
|
||||
for rows.Next() {
|
||||
var queryid pgtype.UUID
|
||||
var queryid *uuid.UUID
|
||||
if err := rows.Scan(&queryid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,15 +2,13 @@ package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -23,7 +21,6 @@ func TestResults(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -48,7 +45,7 @@ func TestResults(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
issynced, err := queries.IsClientSynced(ctx, clientId)
|
||||
issynced, err := queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, issynced)
|
||||
|
||||
@@ -58,7 +55,7 @@ func TestResults(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
issynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
issynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, issynced)
|
||||
|
||||
@@ -70,7 +67,7 @@ func TestResults(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
issynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
issynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, issynced)
|
||||
|
||||
@@ -92,19 +89,24 @@ func TestResults(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
issynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
issynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, issynced)
|
||||
|
||||
textId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: "hi",
|
||||
Key: "hello",
|
||||
Cleanentryid: cleanid,
|
||||
Hash: "example",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
issynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
issynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, issynced)
|
||||
|
||||
@@ -116,7 +118,7 @@ func TestResults(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
issynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
issynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, issynced)
|
||||
|
||||
@@ -130,15 +132,15 @@ func TestResults(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
issynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
issynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, issynced)
|
||||
|
||||
qv := int32(1)
|
||||
res, err := queries.GetResultValueWithVersion(ctx, &repository.GetResultValueWithVersionParams{
|
||||
Queryid: jsonQueryID,
|
||||
Queryid: &jsonQueryID,
|
||||
Queryversion: &qv,
|
||||
Documentid: documentID,
|
||||
Documentid: &documentID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, res.Value)
|
||||
@@ -153,7 +155,6 @@ func TestResultValues(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -213,15 +214,15 @@ func TestResultValues(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
qResults, err := queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: jsonQueryID,
|
||||
Documentid: documentID,
|
||||
Queryid: &jsonQueryID,
|
||||
Documentid: &documentID,
|
||||
Version: &jsonVersion,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qResults, 0)
|
||||
qResults, err = queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: jsonQueryID,
|
||||
Documentid: documentTwoID,
|
||||
Queryid: &jsonQueryID,
|
||||
Documentid: &documentTwoID,
|
||||
Version: &jsonVersion,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -252,11 +253,16 @@ func TestResultValues(t *testing.T) {
|
||||
Version: 1,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
textId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: "hi",
|
||||
Key: "hello",
|
||||
Cleanentryid: cleanid,
|
||||
Hash: "example",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -271,8 +277,8 @@ func TestResultValues(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
qResults, err = queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: jsonQueryID,
|
||||
Documentid: documentID,
|
||||
Queryid: &jsonQueryID,
|
||||
Documentid: &documentID,
|
||||
Version: &jsonVersion,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -280,11 +286,10 @@ func TestResultValues(t *testing.T) {
|
||||
assert.Equal(t, contextQueryID, qResults[0].Queryid)
|
||||
assert.Equal(t, repository.QuerytypeContextFull, qResults[0].Type)
|
||||
assert.Equal(t, "context_value_1", *qResults[0].Value)
|
||||
assert.NotEqual(t, pgtype.UUID{}, qResults[0].ID)
|
||||
assert.True(t, qResults[0].ID.Valid)
|
||||
assert.NotEqual(t, uuid.UUID{}, qResults[0].ID)
|
||||
qResults, err = queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: jsonQueryID,
|
||||
Documentid: documentTwoID,
|
||||
Queryid: &jsonQueryID,
|
||||
Documentid: &documentTwoID,
|
||||
Version: &jsonVersion,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -299,8 +304,8 @@ func TestResultValues(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
qResults, err = queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: jsonQueryID,
|
||||
Documentid: documentID,
|
||||
Queryid: &jsonQueryID,
|
||||
Documentid: &documentID,
|
||||
Version: &jsonVersion,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -308,8 +313,7 @@ func TestResultValues(t *testing.T) {
|
||||
assert.Equal(t, contextQueryID, qResults[0].Queryid)
|
||||
assert.Equal(t, repository.QuerytypeContextFull, qResults[0].Type)
|
||||
assert.Equal(t, "context_value_1", *qResults[0].Value)
|
||||
assert.NotEqual(t, pgtype.UUID{}, qResults[0].ID)
|
||||
assert.True(t, qResults[0].ID.Valid)
|
||||
assert.NotEqual(t, uuid.UUID{}, qResults[0].ID)
|
||||
|
||||
_, err = queries.AddResult(ctx, &repository.AddResultParams{
|
||||
Queryid: contextQueryID,
|
||||
@@ -320,8 +324,8 @@ func TestResultValues(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
qResults, err = queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: jsonQueryID,
|
||||
Documentid: documentID,
|
||||
Queryid: &jsonQueryID,
|
||||
Documentid: &documentID,
|
||||
Version: &jsonVersion,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -329,8 +333,7 @@ func TestResultValues(t *testing.T) {
|
||||
assert.Equal(t, contextQueryID, qResults[0].Queryid)
|
||||
assert.Equal(t, repository.QuerytypeContextFull, qResults[0].Type)
|
||||
assert.Equal(t, "context_value_3", *qResults[0].Value)
|
||||
assert.NotEqual(t, pgtype.UUID{}, qResults[0].ID)
|
||||
assert.True(t, qResults[0].ID.Valid)
|
||||
assert.NotEqual(t, uuid.UUID{}, qResults[0].ID)
|
||||
|
||||
_, err = queries.AddResult(ctx, &repository.AddResultParams{
|
||||
Queryid: jsonQueryID,
|
||||
@@ -341,8 +344,8 @@ func TestResultValues(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
qResults, err = queries.ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: jsonQueryID,
|
||||
Documentid: documentID,
|
||||
Queryid: &jsonQueryID,
|
||||
Documentid: &documentID,
|
||||
Version: &jsonVersion,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
@@ -350,8 +353,7 @@ func TestResultValues(t *testing.T) {
|
||||
assert.Equal(t, contextQueryID, qResults[0].Queryid)
|
||||
assert.Equal(t, repository.QuerytypeContextFull, qResults[0].Type)
|
||||
assert.Equal(t, "context_value_3", *qResults[0].Value)
|
||||
assert.NotEqual(t, pgtype.UUID{}, qResults[0].ID)
|
||||
assert.True(t, qResults[0].ID.Valid)
|
||||
assert.NotEqual(t, uuid.UUID{}, qResults[0].ID)
|
||||
}
|
||||
|
||||
func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
@@ -362,7 +364,6 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -427,10 +428,10 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err := queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err := queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
|
||||
@@ -452,26 +453,30 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
|
||||
textId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: "hi",
|
||||
Key: "hello",
|
||||
Cleanentryid: cleanid,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{contextQueryID}, qs)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&contextQueryID}, qs)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
|
||||
@@ -483,11 +488,11 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, qs)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, qs)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
|
||||
@@ -499,10 +504,10 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
|
||||
@@ -522,20 +527,24 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
|
||||
textTwoId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textTwoId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: "hi",
|
||||
Key: "hello",
|
||||
Cleanentryid: cleantwoid,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textTwoId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = queries.AddResult(ctx, &repository.AddResultParams{
|
||||
Queryid: contextQueryID,
|
||||
@@ -545,13 +554,13 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, qs)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, qs)
|
||||
|
||||
_, err = queries.AddResult(ctx, &repository.AddResultParams{
|
||||
Queryid: jsonQueryID,
|
||||
@@ -561,10 +570,10 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 0)
|
||||
|
||||
@@ -576,12 +585,12 @@ func TestUnsyncedNoDepsQueries(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentID)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, qs)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, documentTwoID)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, qs)
|
||||
qs, err = queries.ListUnsyncedNoDepsQueriesByDocId(ctx, &documentTwoID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, qs, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{jsonQueryID}, qs)
|
||||
assert.ElementsMatch(t, []*uuid.UUID{&jsonQueryID}, qs)
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database/repository"
|
||||
@@ -22,7 +20,6 @@ func TestListClientDocumentIDs(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -61,7 +58,7 @@ func TestListClientDocumentIDs(t *testing.T) {
|
||||
total := int64(1)
|
||||
assert.ElementsMatch(t, []*repository.ListDocumentIDsBatchRow{
|
||||
{
|
||||
ID: docOne,
|
||||
ID: &docOne,
|
||||
Totalcount: &total,
|
||||
},
|
||||
}, ids)
|
||||
@@ -82,7 +79,7 @@ func TestListClientDocumentIDs(t *testing.T) {
|
||||
total = int64(2)
|
||||
assert.ElementsMatch(t, []*repository.ListDocumentIDsBatchRow{
|
||||
{
|
||||
ID: docOne,
|
||||
ID: &docOne,
|
||||
Totalcount: &total,
|
||||
},
|
||||
}, ids)
|
||||
@@ -96,7 +93,7 @@ func TestListClientDocumentIDs(t *testing.T) {
|
||||
assert.Len(t, ids, 1)
|
||||
assert.ElementsMatch(t, []*repository.ListDocumentIDsBatchRow{
|
||||
{
|
||||
ID: docTwo,
|
||||
ID: &docTwo,
|
||||
Totalcount: &total,
|
||||
},
|
||||
}, ids)
|
||||
@@ -110,11 +107,11 @@ func TestListClientDocumentIDs(t *testing.T) {
|
||||
assert.Len(t, ids, 2)
|
||||
assert.ElementsMatch(t, []*repository.ListDocumentIDsBatchRow{
|
||||
{
|
||||
ID: docOne,
|
||||
ID: &docOne,
|
||||
Totalcount: &total,
|
||||
},
|
||||
{
|
||||
ID: docTwo,
|
||||
ID: &docTwo,
|
||||
Totalcount: &total,
|
||||
},
|
||||
}, ids)
|
||||
@@ -128,7 +125,6 @@ func TestClientSync(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -184,7 +180,7 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err := queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err := queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
|
||||
@@ -197,7 +193,7 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
docExternal, err := queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err := queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -206,7 +202,7 @@ func TestClientSync(t *testing.T) {
|
||||
Fields: []byte(`{"first_key": null}`),
|
||||
}, docExternal)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
|
||||
@@ -224,10 +220,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -244,11 +240,11 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
|
||||
docExternal, err := queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err := queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -274,10 +270,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -286,18 +282,23 @@ func TestClientSync(t *testing.T) {
|
||||
Fields: []byte(`{"first_key": null}`),
|
||||
}, docExternal)
|
||||
|
||||
textId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: "hi",
|
||||
Key: "hello",
|
||||
Cleanentryid: cleanId,
|
||||
Hash: "example",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -315,10 +316,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -335,10 +336,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -353,11 +354,11 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -375,10 +376,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -396,10 +397,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -416,10 +417,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -434,10 +435,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -448,18 +449,22 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("update text entry", func(t *testing.T) {
|
||||
textId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: "hi",
|
||||
Key: "hello",
|
||||
Cleanentryid: cleanId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -476,10 +481,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -496,10 +501,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -514,10 +519,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -543,10 +548,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -555,18 +560,22 @@ func TestClientSync(t *testing.T) {
|
||||
Fields: []byte(`{"first_key": null}`),
|
||||
}, docExternal)
|
||||
|
||||
textThreeId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textThreeId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: "hi",
|
||||
Key: "hello",
|
||||
Cleanentryid: cleanthreeid,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textThreeId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -583,10 +592,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -603,10 +612,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -621,10 +630,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -636,10 +645,10 @@ func TestClientSync(t *testing.T) {
|
||||
latestCollectorVersion, err := queries.AddLatestCollectorVersion(ctx, clientId)
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -655,10 +664,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -674,10 +683,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -694,10 +703,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -716,10 +725,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -754,10 +763,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -774,10 +783,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -794,10 +803,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -812,10 +821,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
@@ -830,10 +839,10 @@ func TestClientSync(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isSynced, err = queries.IsClientSynced(ctx, clientId)
|
||||
isSynced, err = queries.IsClientSynced(ctx, &clientId)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, isSynced)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, documentID)
|
||||
docExternal, err = queries.GetDocumentExternal(ctx, &documentID)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &repository.GetDocumentExternalRow{
|
||||
ID: documentID,
|
||||
|
||||
@@ -8,47 +8,95 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const addDocumentTextEntry = `-- name: AddDocumentTextEntry :one
|
||||
INSERT INTO documentTextExtractions (version, bucket, key, cleanEntryId) VALUES ($1, $2, $3, $4) returning id
|
||||
const addDocumentText = `-- name: AddDocumentText :one
|
||||
INSERT INTO documentTextExtractions (bucket, key, cleanEntryId, hash) VALUES ($1, $2, $3, $4) returning id
|
||||
`
|
||||
|
||||
type AddDocumentTextEntryParams struct {
|
||||
Version int64 `db:"version"`
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Cleanentryid pgtype.UUID `db:"cleanentryid"`
|
||||
type AddDocumentTextParams struct {
|
||||
Bucket string `db:"bucket"`
|
||||
Key string `db:"key"`
|
||||
Cleanentryid uuid.UUID `db:"cleanentryid"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
// AddDocumentTextEntry
|
||||
// AddDocumentText
|
||||
//
|
||||
// INSERT INTO documentTextExtractions (version, bucket, key, cleanEntryId) VALUES ($1, $2, $3, $4) returning id
|
||||
func (q *Queries) AddDocumentTextEntry(ctx context.Context, arg *AddDocumentTextEntryParams) (pgtype.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, addDocumentTextEntry,
|
||||
arg.Version,
|
||||
// INSERT INTO documentTextExtractions (bucket, key, cleanEntryId, hash) VALUES ($1, $2, $3, $4) returning id
|
||||
func (q *Queries) AddDocumentText(ctx context.Context, arg *AddDocumentTextParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, addDocumentText,
|
||||
arg.Bucket,
|
||||
arg.Key,
|
||||
arg.Cleanentryid,
|
||||
arg.Hash,
|
||||
)
|
||||
var id pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const addDocumentTextEntry = `-- name: AddDocumentTextEntry :exec
|
||||
INSERT INTO documentTextExtractionEntries (textId, version) VALUES ($1, $2)
|
||||
`
|
||||
|
||||
type AddDocumentTextEntryParams struct {
|
||||
Textid uuid.UUID `db:"textid"`
|
||||
Version int64 `db:"version"`
|
||||
}
|
||||
|
||||
// AddDocumentTextEntry
|
||||
//
|
||||
// INSERT INTO documentTextExtractionEntries (textId, version) VALUES ($1, $2)
|
||||
func (q *Queries) AddDocumentTextEntry(ctx context.Context, arg *AddDocumentTextEntryParams) error {
|
||||
_, err := q.db.Exec(ctx, addDocumentTextEntry, arg.Textid, arg.Version)
|
||||
return err
|
||||
}
|
||||
|
||||
const getDocumentTextExtractionByHash = `-- name: GetDocumentTextExtractionByHash :one
|
||||
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
FROM currentTextEntries
|
||||
WHERE cleanEntryId = $1 and hash = $2
|
||||
`
|
||||
|
||||
type GetDocumentTextExtractionByHashParams struct {
|
||||
Cleanentryid uuid.UUID `db:"cleanentryid"`
|
||||
Hash string `db:"hash"`
|
||||
}
|
||||
|
||||
// GetDocumentTextExtractionByHash
|
||||
//
|
||||
// SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
// FROM currentTextEntries
|
||||
// WHERE cleanEntryId = $1 and hash = $2
|
||||
func (q *Queries) GetDocumentTextExtractionByHash(ctx context.Context, arg *GetDocumentTextExtractionByHashParams) (*Currenttextentry, error) {
|
||||
row := q.db.QueryRow(ctx, getDocumentTextExtractionByHash, arg.Cleanentryid, arg.Hash)
|
||||
var i Currenttextentry
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Documentid,
|
||||
&i.Bucket,
|
||||
&i.Key,
|
||||
&i.Version,
|
||||
&i.Hash,
|
||||
&i.Cleanentryid,
|
||||
)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const getTextEntryByDocId = `-- name: GetTextEntryByDocId :one
|
||||
SELECT id, documentId, bucket, key, version, cleanEntryId
|
||||
SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
FROM currentTextEntries
|
||||
WHERE documentId = $1
|
||||
`
|
||||
|
||||
// GetTextEntryByDocId
|
||||
//
|
||||
// SELECT id, documentId, bucket, key, version, cleanEntryId
|
||||
// SELECT id, documentId, bucket, key, version, hash, cleanEntryId
|
||||
// FROM currentTextEntries
|
||||
// WHERE documentId = $1
|
||||
func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid pgtype.UUID) (*Currenttextentry, error) {
|
||||
func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid uuid.UUID) (*Currenttextentry, error) {
|
||||
row := q.db.QueryRow(ctx, getTextEntryByDocId, documentid)
|
||||
var i Currenttextentry
|
||||
err := row.Scan(
|
||||
@@ -57,6 +105,7 @@ func (q *Queries) GetTextEntryByDocId(ctx context.Context, documentid pgtype.UUI
|
||||
&i.Bucket,
|
||||
&i.Key,
|
||||
&i.Version,
|
||||
&i.Hash,
|
||||
&i.Cleanentryid,
|
||||
)
|
||||
return &i, err
|
||||
@@ -73,7 +122,7 @@ SELECT EXISTS(
|
||||
// SELECT EXISTS(
|
||||
// SELECT 1 FROM currentTextEntries WHERE documentId = $1
|
||||
// )
|
||||
func (q *Queries) IsDocumentTextExtracted(ctx context.Context, documentid pgtype.UUID) (bool, error) {
|
||||
func (q *Queries) IsDocumentTextExtracted(ctx context.Context, documentid uuid.UUID) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, isDocumentTextExtracted, documentid)
|
||||
var exists bool
|
||||
err := row.Scan(&exists)
|
||||
|
||||
@@ -2,15 +2,13 @@ package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/test"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -23,7 +21,6 @@ func TestTextExtraction(t *testing.T) {
|
||||
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
test.SetCfgProvider(t, cfg)
|
||||
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
||||
_, textup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
||||
Cfg: cfg,
|
||||
RunMigrations: true,
|
||||
@@ -68,15 +65,25 @@ func TestTextExtraction(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isextract)
|
||||
|
||||
textId, err := queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
textId, err := queries.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
Cleanentryid: cleanid,
|
||||
Hash: "example",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, textId)
|
||||
assert.NotEqual(t, pgtype.UUID{}, textId)
|
||||
assert.NotEqual(t, uuid.UUID{}, textId)
|
||||
|
||||
isextract, err = queries.IsDocumentTextExtracted(ctx, id)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, isextract)
|
||||
|
||||
err = queries.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: 1,
|
||||
Textid: textId,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
isextract, err = queries.IsDocumentTextExtracted(ctx, id)
|
||||
require.NoError(t, err)
|
||||
@@ -89,4 +96,17 @@ func TestTextExtraction(t *testing.T) {
|
||||
assert.Equal(t, key, text.Key)
|
||||
assert.Equal(t, int64(1), text.Version)
|
||||
assert.Equal(t, textId, text.ID)
|
||||
|
||||
uniqueEntry, err := queries.GetDocumentTextExtractionByHash(ctx, &repository.GetDocumentTextExtractionByHashParams{
|
||||
Hash: "example",
|
||||
Cleanentryid: cleanid,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, text, uniqueEntry)
|
||||
|
||||
_, err = queries.GetDocumentTextExtractionByHash(ctx, &repository.GetDocumentTextExtractionByHashParams{
|
||||
Hash: "definitely invalid",
|
||||
Cleanentryid: cleanid,
|
||||
})
|
||||
require.EqualError(t, err, "no rows in result set")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user