Merged in feature/textextract (pull request #108)
Start adding Textract + UUID changes * base * startclient * ts * short * tests
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -31,7 +30,7 @@ func (s *Service) Create(ctx context.Context, params CreateParams) (uuid.UUID, e
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
return database.MustToUUID(id), nil
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (s *Service) normalizeCreate(params *CreateParams) error {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
@@ -34,7 +33,7 @@ func TestCreate(t *testing.T) {
|
||||
pool.ExpectQuery("name: CreateClient :one").WithArgs(params.ExternalId, params.Name).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(aid)),
|
||||
AddRow(aid),
|
||||
)
|
||||
|
||||
id, err := svc.Create(ctx, params)
|
||||
|
||||
@@ -3,14 +3,13 @@ package client
|
||||
import (
|
||||
"context"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Client, error) {
|
||||
client, err := s.cfg.GetDBQueries().GetClient(ctx, database.MustToDBUUID(id))
|
||||
client, err := s.cfg.GetDBQueries().GetClient(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -29,7 +28,7 @@ func (s *Service) GetByExternalId(ctx context.Context, id string) (*Client, erro
|
||||
|
||||
func parseFullClient(client *repository.Fullclient) *Client {
|
||||
return &Client{
|
||||
ID: database.MustToUUID(client.ID),
|
||||
ID: client.ID,
|
||||
ExternalID: client.Externalid,
|
||||
Name: client.Name,
|
||||
CanSync: client.Cansync,
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
@@ -28,10 +27,10 @@ func TestGet(t *testing.T) {
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(id)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(id).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(id), "client_id", "client_name", false),
|
||||
AddRow(id, "client_id", "client_name", false),
|
||||
)
|
||||
|
||||
cli, err := svc.Get(ctx, id)
|
||||
@@ -44,7 +43,7 @@ func TestGet(t *testing.T) {
|
||||
}, cli)
|
||||
|
||||
dberr := "database failure"
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(id)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(id).
|
||||
WillReturnError(errors.New(dberr))
|
||||
|
||||
_, err = svc.Get(ctx, id)
|
||||
@@ -68,7 +67,7 @@ func TestGetByExternalId(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(externalId).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(id), "client_id", "client_name", false),
|
||||
AddRow(id, "client_id", "client_name", false),
|
||||
)
|
||||
|
||||
cli, err := svc.GetByExternalId(ctx, externalId)
|
||||
@@ -81,7 +80,7 @@ func TestGetByExternalId(t *testing.T) {
|
||||
}, cli)
|
||||
|
||||
dberr := "database failure"
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(id)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(id).
|
||||
WillReturnError(errors.New(dberr))
|
||||
|
||||
_, err = svc.Get(ctx, id)
|
||||
@@ -90,14 +89,14 @@ func TestGetByExternalId(t *testing.T) {
|
||||
|
||||
func TestParseFullClient(t *testing.T) {
|
||||
in := &repository.Fullclient{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Externalid: "external_id",
|
||||
Name: "name",
|
||||
Cansync: true,
|
||||
}
|
||||
out := parseFullClient(in)
|
||||
assert.EqualExportedValues(t, &Client{
|
||||
ID: database.MustToUUID(in.ID),
|
||||
ID: in.ID,
|
||||
ExternalID: "external_id",
|
||||
Name: "name",
|
||||
CanSync: true,
|
||||
|
||||
@@ -20,7 +20,7 @@ func (s *Service) GetStatusByExternalId(ctx context.Context, id string) (Status,
|
||||
return NOT_SYNCING, nil
|
||||
}
|
||||
|
||||
issynced, err := s.cfg.GetDBQueries().IsClientSynced(ctx, client.ID)
|
||||
issynced, err := s.cfg.GetDBQueries().IsClientSynced(ctx, &client.ID)
|
||||
if err != nil {
|
||||
return NOT_SYNCING, err
|
||||
} else if issynced {
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
@@ -33,9 +32,9 @@ func TestGetStatusByExternalId(t *testing.T) {
|
||||
t.Run("is synced", func(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(externalId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "can_sync"}).
|
||||
AddRow(database.MustToDBUUID(clientId), externalId, "name", true),
|
||||
AddRow(clientId, externalId, "name", true),
|
||||
)
|
||||
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(database.MustToDBUUID(clientId)).WillReturnRows(
|
||||
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(&clientId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"issynced"}).
|
||||
AddRow(true),
|
||||
)
|
||||
@@ -47,9 +46,9 @@ func TestGetStatusByExternalId(t *testing.T) {
|
||||
t.Run("not synced", func(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(externalId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "can_sync"}).
|
||||
AddRow(database.MustToDBUUID(clientId), externalId, "name", true),
|
||||
AddRow(clientId, externalId, "name", true),
|
||||
)
|
||||
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(database.MustToDBUUID(clientId)).WillReturnRows(
|
||||
pool.ExpectQuery("name: IsClientSynced :one").WithArgs(&clientId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"issynced"}).
|
||||
AddRow(false),
|
||||
)
|
||||
@@ -61,7 +60,7 @@ func TestGetStatusByExternalId(t *testing.T) {
|
||||
t.Run("not syncing", func(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(externalId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "can_sync"}).
|
||||
AddRow(database.MustToDBUUID(clientId), "id", "name", false),
|
||||
AddRow(clientId, "id", "name", false),
|
||||
)
|
||||
|
||||
issynced, err := svc.GetStatusByExternalId(ctx, externalId)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"log/slog"
|
||||
|
||||
docsyncrunner "queryorchestration/api/docSyncRunner"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
|
||||
@@ -17,7 +16,7 @@ import (
|
||||
func (s *Service) Sync(ctx context.Context, id uuid.UUID) error {
|
||||
hasMore := true
|
||||
offset := int32(0)
|
||||
dbid := database.MustToDBUUID(id)
|
||||
dbid := id
|
||||
|
||||
for hasMore {
|
||||
ids, err := s.cfg.GetDBQueries().ListDocumentIDsBatch(ctx, &repository.ListDocumentIDsBatchParams{
|
||||
@@ -37,7 +36,7 @@ func (s *Service) Sync(ctx context.Context, id uuid.UUID) error {
|
||||
err := s.cfg.SendToQueue(ctx, &queue.SendParams{
|
||||
QueueURL: s.cfg.GetDocumentSyncURL(),
|
||||
Body: docsyncrunner.Body{
|
||||
ID: database.MustToUUID(id.ID),
|
||||
ID: *id.ID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -54,10 +53,10 @@ func TestTrigger(t *testing.T) {
|
||||
|
||||
svc.batchSize = 1
|
||||
total := int64(2)
|
||||
pool.ExpectQuery("name: ListDocumentIDsBatch :many").WithArgs(database.MustToDBUUID(clientId), svc.batchSize, int32(0)).
|
||||
pool.ExpectQuery("name: ListDocumentIDsBatch :many").WithArgs(clientId, svc.batchSize, int32(0)).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "totalCount"}).
|
||||
AddRow(database.MustToDBUUID(docs[0].ID), &total),
|
||||
AddRow(&docs[0].ID, &total),
|
||||
)
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
@@ -68,10 +67,10 @@ func TestTrigger(t *testing.T) {
|
||||
mock.Anything,
|
||||
).
|
||||
Return(&sqs.SendMessageOutput{}, nil)
|
||||
pool.ExpectQuery("name: ListDocumentIDsBatch :many").WithArgs(database.MustToDBUUID(clientId), svc.batchSize, int32(1)).
|
||||
pool.ExpectQuery("name: ListDocumentIDsBatch :many").WithArgs(clientId, svc.batchSize, int32(1)).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "totalCount"}).
|
||||
AddRow(database.MustToDBUUID(docs[1].ID), &total),
|
||||
AddRow(&docs[1].ID, &total),
|
||||
)
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
@@ -104,7 +103,7 @@ func TestTrigger(t *testing.T) {
|
||||
clientId := uuid.New()
|
||||
|
||||
svc.batchSize = 1
|
||||
pool.ExpectQuery("name: ListDocumentIDsBatch :many").WithArgs(database.MustToDBUUID(clientId), svc.batchSize, int32(0)).
|
||||
pool.ExpectQuery("name: ListDocumentIDsBatch :many").WithArgs(clientId, svc.batchSize, int32(0)).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "totalCount"}),
|
||||
)
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"log/slog"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/validation"
|
||||
|
||||
@@ -18,7 +17,7 @@ func (s *Service) UpdateByExternalId(ctx context.Context, id string, entity *Upd
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.Update(ctx, database.MustToUUID(client.ID), entity)
|
||||
err = s.Update(ctx, client.ID, entity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -52,7 +51,7 @@ func (s *Service) Update(ctx context.Context, id uuid.UUID, entity *Update) erro
|
||||
|
||||
func (s *Service) submitUpdate(ctx context.Context, id uuid.UUID, entity *Update) error {
|
||||
return s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
id := database.MustToDBUUID(id)
|
||||
id := id
|
||||
|
||||
if entity.Name != nil {
|
||||
err := q.UpdateClient(ctx, &repository.UpdateClientParams{
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
@@ -32,10 +31,10 @@ func TestUpdate(t *testing.T) {
|
||||
}
|
||||
update := Update{}
|
||||
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(c.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(c.ID), c.Name, c.CanSync),
|
||||
AddRow(c.ID, c.Name, c.CanSync),
|
||||
)
|
||||
|
||||
err = svc.Update(ctx, c.ID, &update)
|
||||
@@ -44,10 +43,10 @@ func TestUpdate(t *testing.T) {
|
||||
c.CanSync = false
|
||||
update.CanSync = &c.CanSync
|
||||
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(c.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(c.ID), c.Name, c.CanSync),
|
||||
AddRow(c.ID, c.Name, c.CanSync),
|
||||
)
|
||||
|
||||
err = svc.Update(ctx, c.ID, &update)
|
||||
@@ -56,12 +55,12 @@ func TestUpdate(t *testing.T) {
|
||||
c.Name = "updated_name"
|
||||
update.Name = &c.Name
|
||||
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(c.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(c.ID), c.Name, c.CanSync),
|
||||
AddRow(c.ID, c.Name, c.CanSync),
|
||||
)
|
||||
pool.ExpectExec("name: UpdateClient :exec").WithArgs(*update.Name, database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectExec("name: UpdateClient :exec").WithArgs(*update.Name, c.ID).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
|
||||
err = svc.Update(ctx, c.ID, &update)
|
||||
@@ -134,7 +133,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
update.CanSync = &c.CanSync
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectExec("name: AddClientCanSync :exec").WithArgs(*update.CanSync, database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectExec("name: AddClientCanSync :exec").WithArgs(*update.CanSync, c.ID).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -146,7 +145,7 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
update.CanSync = nil
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectExec("name: UpdateClient :exec").WithArgs(*update.Name, database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectExec("name: UpdateClient :exec").WithArgs(*update.Name, c.ID).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -177,13 +176,13 @@ func TestUpdateByExternalId(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(c.ExternalID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(c.ID), c.ExternalID, c.Name, c.CanSync),
|
||||
AddRow(c.ID, c.ExternalID, c.Name, c.CanSync),
|
||||
)
|
||||
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(c.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(c.ID), c.ExternalID, c.Name, c.CanSync),
|
||||
AddRow(c.ID, c.ExternalID, c.Name, c.CanSync),
|
||||
)
|
||||
|
||||
err = svc.UpdateByExternalId(ctx, c.ExternalID, &update)
|
||||
@@ -194,10 +193,10 @@ func TestUpdateByExternalId(t *testing.T) {
|
||||
c.CanSync = false
|
||||
update.CanSync = &c.CanSync
|
||||
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(c.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(c.ID), c.Name, c.CanSync),
|
||||
AddRow(c.ID, c.Name, c.CanSync),
|
||||
)
|
||||
|
||||
err = svc.UpdateByExternalId(ctx, c.ExternalID, &update)
|
||||
@@ -208,12 +207,12 @@ func TestUpdateByExternalId(t *testing.T) {
|
||||
c.Name = "updated_name"
|
||||
update.Name = &c.Name
|
||||
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(c.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(c.ID), c.Name, c.CanSync),
|
||||
AddRow(c.ID, c.Name, c.CanSync),
|
||||
)
|
||||
pool.ExpectExec("name: UpdateClient :exec").WithArgs(*update.Name, database.MustToDBUUID(c.ID)).
|
||||
pool.ExpectExec("name: UpdateClient :exec").WithArgs(*update.Name, c.ID).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
|
||||
err = svc.UpdateByExternalId(ctx, c.ExternalID, &update)
|
||||
|
||||
@@ -3,7 +3,6 @@ package collector
|
||||
import (
|
||||
"context"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -19,7 +18,7 @@ func (s *Service) GetByClientExternalID(ctx context.Context, clientID string) (*
|
||||
}
|
||||
|
||||
func (s *Service) GetByClientID(ctx context.Context, clientID uuid.UUID) (*Collector, error) {
|
||||
dbColl, err := s.cfg.GetDBQueries().GetCollectorByClientID(ctx, database.MustToDBUUID(clientID))
|
||||
dbColl, err := s.cfg.GetDBQueries().GetCollectorByClientID(ctx, clientID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -28,7 +27,7 @@ func (s *Service) GetByClientID(ctx context.Context, clientID uuid.UUID) (*Colle
|
||||
}
|
||||
|
||||
func (s *Service) ListQueries(ctx context.Context, id uuid.UUID) ([]*resultprocessor.Query, error) {
|
||||
queries, err := s.cfg.GetDBQueries().ListCollectorQueries(ctx, database.MustToDBUUID(id))
|
||||
queries, err := s.cfg.GetDBQueries().ListCollectorQueries(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -39,10 +38,10 @@ func TestGetByClientID(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(ogc.ClientID)).
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(ogc.ClientID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||
AddRow(database.MustToDBUUID(ogc.ClientID), ogc.MinCleanVersion, ogc.MinTextVersion, ogc.ActiveVersion, ogc.LatestVersion, []byte(fmt.Sprintf("{\"example_key\":\"%s\"}", ogc.Fields["example_key"].String()))),
|
||||
AddRow(ogc.ClientID, ogc.MinCleanVersion, ogc.MinTextVersion, ogc.ActiveVersion, ogc.LatestVersion, []byte(fmt.Sprintf("{\"example_key\":\"%s\"}", ogc.Fields["example_key"].String()))),
|
||||
)
|
||||
|
||||
coll, err := svc.GetByClientID(ctx, ogc.ClientID)
|
||||
@@ -70,13 +69,14 @@ func TestListQueries(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: ListCollectorQueries :many").WithArgs(database.MustToDBUUID(clientId)).
|
||||
pool.ExpectQuery("name: ListCollectorQueries :many").WithArgs(clientId).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"clientId", "queryId", "type", "queryVersion", "requiredIds"}).
|
||||
AddRow(database.MustToDBUUID(clientId), database.MustToDBUUID(ogc[0].ID), repository.QuerytypeContextFull, int32(2), nil),
|
||||
AddRow(clientId, &ogc[0].ID, repository.QuerytypeContextFull, int32(2), nil),
|
||||
)
|
||||
|
||||
qs, err := svc.ListQueries(ctx, clientId)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, ogc, qs)
|
||||
assert.Len(t, qs, 1)
|
||||
assert.EqualExportedValues(t, *ogc[0], *qs[0])
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -27,7 +26,7 @@ func parseDBCollector(c *repository.Fullactivecollector) (*Collector, error) {
|
||||
}
|
||||
|
||||
return &Collector{
|
||||
ClientID: database.MustToUUID(c.Clientid),
|
||||
ClientID: c.Clientid,
|
||||
MinCleanVersion: c.Mincleanversion,
|
||||
MinTextVersion: c.Mintextversion,
|
||||
ActiveVersion: c.Activeversion,
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -28,7 +27,7 @@ func TestParseDBCollector(t *testing.T) {
|
||||
},
|
||||
}
|
||||
c, err = parseDBCollector(&repository.Fullactivecollector{
|
||||
Clientid: database.MustToDBUUID(ogc.ClientID),
|
||||
Clientid: ogc.ClientID,
|
||||
Mincleanversion: ogc.MinCleanVersion,
|
||||
Mintextversion: ogc.MinTextVersion,
|
||||
Fields: []byte(fmt.Sprintf("{\"example_key\":\"%s\"}", ogc.Fields["example_key"])),
|
||||
@@ -39,7 +38,7 @@ func TestParseDBCollector(t *testing.T) {
|
||||
ogc.MinCleanVersion = 0
|
||||
ogc.MinTextVersion = 0
|
||||
c, err = parseDBCollector(&repository.Fullactivecollector{
|
||||
Clientid: database.MustToDBUUID(ogc.ClientID),
|
||||
Clientid: ogc.ClientID,
|
||||
Fields: []byte(fmt.Sprintf("{\"example_key\":\"%s\"}", ogc.Fields["example_key"])),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -7,14 +7,12 @@ import (
|
||||
|
||||
clientsyncrunner "queryorchestration/api/clientSyncRunner"
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig/build"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
"queryorchestration/internal/validation"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func (s *Service) SetByClientExternalId(ctx context.Context, id string, params *SetParams) error {
|
||||
@@ -23,7 +21,7 @@ func (s *Service) SetByClientExternalId(ctx context.Context, id string, params *
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.SetByClientId(ctx, database.MustToUUID(client.ID), params)
|
||||
err = s.SetByClientId(ctx, client.ID, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -70,17 +68,17 @@ func (s *Service) informSet(ctx context.Context, update *dbSetParams) error {
|
||||
return s.cfg.SendToQueue(ctx, &queue.SendParams{
|
||||
QueueURL: s.cfg.GetClientSyncURL(),
|
||||
Body: clientsyncrunner.Body{
|
||||
ID: database.MustToUUID(update.ClientID),
|
||||
ID: update.ClientID,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type dbSetParams struct {
|
||||
ClientID pgtype.UUID
|
||||
ClientID uuid.UUID
|
||||
ActiveVersion *int32
|
||||
MinCleanVersion *int64
|
||||
MinTextVersion *int64
|
||||
Fields *map[string]pgtype.UUID
|
||||
Fields *map[string]uuid.UUID
|
||||
}
|
||||
|
||||
func (s *Service) getSetParams(ctx context.Context, id uuid.UUID, current *collector.Collector, params *SetParams) (*dbSetParams, error) {
|
||||
@@ -115,7 +113,7 @@ func (s *Service) getSetParams(ctx context.Context, id uuid.UUID, current *colle
|
||||
}
|
||||
|
||||
return &dbSetParams{
|
||||
ClientID: database.MustToDBUUID(id),
|
||||
ClientID: id,
|
||||
ActiveVersion: params.ActiveVersion,
|
||||
MinCleanVersion: params.MinCleanVersion,
|
||||
MinTextVersion: params.MinTextVersion,
|
||||
@@ -174,16 +172,16 @@ func (s *Service) normalizeActiveVersion(current *collector.Collector, params *S
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) normalizeSetFieldsToDB(ctx context.Context, current map[string]uuid.UUID, ofields *map[string]uuid.UUID) (*map[string]pgtype.UUID, error) {
|
||||
func (s *Service) normalizeSetFieldsToDB(ctx context.Context, current map[string]uuid.UUID, ofields *map[string]uuid.UUID) (*map[string]uuid.UUID, error) {
|
||||
if ofields == nil || *ofields == nil {
|
||||
return nil, nil
|
||||
} else if len(*ofields) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
dbm := map[string]pgtype.UUID{}
|
||||
dbm := map[string]uuid.UUID{}
|
||||
for name, id := range *ofields {
|
||||
dbm[name] = database.MustToDBUUID(id)
|
||||
dbm[name] = id
|
||||
}
|
||||
|
||||
removeIDs := getRemoveFields(current, &dbm)
|
||||
@@ -282,8 +280,8 @@ func (s *Service) submitSet(ctx context.Context, current *collector.Collector, p
|
||||
return nil
|
||||
}
|
||||
|
||||
func getRemoveFields(current map[string]uuid.UUID, update *map[string]pgtype.UUID) []pgtype.UUID {
|
||||
diff := []pgtype.UUID{}
|
||||
func getRemoveFields(current map[string]uuid.UUID, update *map[string]uuid.UUID) []uuid.UUID {
|
||||
diff := []uuid.UUID{}
|
||||
if update == nil {
|
||||
return diff
|
||||
}
|
||||
@@ -291,27 +289,27 @@ func getRemoveFields(current map[string]uuid.UUID, update *map[string]pgtype.UUI
|
||||
for ckey, cid := range current {
|
||||
found := false
|
||||
for ukey, uid := range *update {
|
||||
if cid == database.MustToUUID(uid) &&
|
||||
if cid == uid &&
|
||||
ckey == ukey {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
diff = append(diff, database.MustToDBUUID(cid))
|
||||
diff = append(diff, cid)
|
||||
}
|
||||
}
|
||||
|
||||
return diff
|
||||
}
|
||||
|
||||
func getAddFields(current map[string]uuid.UUID, update *map[string]pgtype.UUID) map[string]pgtype.UUID {
|
||||
diff := map[string]pgtype.UUID{}
|
||||
func getAddFields(current map[string]uuid.UUID, update *map[string]uuid.UUID) map[string]uuid.UUID {
|
||||
diff := map[string]uuid.UUID{}
|
||||
if update == nil {
|
||||
return diff
|
||||
}
|
||||
|
||||
for ukey, uid := range *update {
|
||||
if current[ukey] != database.MustToUUID(uid) {
|
||||
if current[ukey] != uid {
|
||||
diff[ukey] = uid
|
||||
}
|
||||
}
|
||||
@@ -319,19 +317,19 @@ func getAddFields(current map[string]uuid.UUID, update *map[string]pgtype.UUID)
|
||||
return diff
|
||||
}
|
||||
|
||||
func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields *map[string]uuid.UUID) (*map[string]pgtype.UUID, error) {
|
||||
func (s *Service) normalizeFieldsToDB(ctx context.Context, ofields *map[string]uuid.UUID) (*map[string]uuid.UUID, error) {
|
||||
if ofields == nil || *ofields == nil {
|
||||
return nil, nil
|
||||
} else if len(*ofields) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
dbm := map[string]pgtype.UUID{}
|
||||
dbm := map[string]uuid.UUID{}
|
||||
for name, id := range *ofields {
|
||||
dbm[name] = database.MustToDBUUID(id)
|
||||
dbm[name] = id
|
||||
}
|
||||
|
||||
dbids := []pgtype.UUID{}
|
||||
dbids := []uuid.UUID{}
|
||||
for _, id := range dbm {
|
||||
dbids = append(dbids, id)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"queryorchestration/internal/collector"
|
||||
collectorset "queryorchestration/internal/collector/set"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
||||
@@ -55,20 +54,20 @@ func TestSet(t *testing.T) {
|
||||
MinCleanVersion: &mv,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(current.ClientID)).
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(current.ClientID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||
AddRow(database.MustToDBUUID(current.ClientID), current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
AddRow(current.ClientID, current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
)
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
rv := current.LatestVersion + 1
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(current.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(rv),
|
||||
)
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(2)).
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(current.ClientID, int32(2)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *update.MinCleanVersion).
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(current.ClientID, rv, *update.MinCleanVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -96,20 +95,20 @@ func TestSet(t *testing.T) {
|
||||
MinCleanVersion: &mv,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(current.ClientID)).
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(current.ClientID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||
AddRow(database.MustToDBUUID(current.ClientID), current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
AddRow(current.ClientID, current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
)
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
rv := current.LatestVersion + 1
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(current.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(rv),
|
||||
)
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(1)).
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(current.ClientID, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *update.MinCleanVersion).
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(current.ClientID, rv, *update.MinCleanVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -161,22 +160,22 @@ func TestSetByExternalId(t *testing.T) {
|
||||
|
||||
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(externalId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "can_sync"}).
|
||||
AddRow(database.MustToDBUUID(current.ClientID), externalId, "name", true),
|
||||
AddRow(current.ClientID, externalId, "name", true),
|
||||
)
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(current.ClientID)).
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(current.ClientID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||
AddRow(database.MustToDBUUID(current.ClientID), current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
AddRow(current.ClientID, current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
)
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
rv := current.LatestVersion + 1
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(current.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(rv),
|
||||
)
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(2)).
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(current.ClientID, int32(2)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *update.MinCleanVersion).
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(current.ClientID, rv, *update.MinCleanVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -206,22 +205,22 @@ func TestSetByExternalId(t *testing.T) {
|
||||
|
||||
pool.ExpectQuery("name: GetClientByExternalId :one").WithArgs(externalId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "can_sync"}).
|
||||
AddRow(database.MustToDBUUID(current.ClientID), externalId, "name", true),
|
||||
AddRow(current.ClientID, externalId, "name", true),
|
||||
)
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(database.MustToDBUUID(current.ClientID)).
|
||||
pool.ExpectQuery("name: GetCollectorByClientID :one").WithArgs(current.ClientID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"clientId", "minCleanVersion", "minTextVersion", "activeVersion", "latestVersion", "fields"}).
|
||||
AddRow(database.MustToDBUUID(current.ClientID), current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
AddRow(current.ClientID, current.MinCleanVersion, current.MinTextVersion, current.ActiveVersion, current.LatestVersion, []byte("")),
|
||||
)
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
rv := current.LatestVersion + 1
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(current.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(rv),
|
||||
)
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(1)).
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(current.ClientID, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *update.MinCleanVersion).
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(current.ClientID, rv, *update.MinCleanVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/collector"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/queue/clientsync"
|
||||
@@ -15,7 +14,6 @@ import (
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -60,7 +58,7 @@ func TestGetSetParams(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{(*params.Fields)["example_key"]})).WillReturnRows(
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs([]uuid.UUID{(*params.Fields)["example_key"]}).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
AddRow(true),
|
||||
)
|
||||
@@ -70,12 +68,12 @@ func TestGetSetParams(t *testing.T) {
|
||||
dbparams, err := svc.getSetParams(ctx, clientId, ¤t, ¶ms)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &dbSetParams{
|
||||
ClientID: database.MustToDBUUID(clientId),
|
||||
ClientID: clientId,
|
||||
ActiveVersion: &aV,
|
||||
MinCleanVersion: &minCleanV,
|
||||
MinTextVersion: &minTextV,
|
||||
Fields: &map[string]pgtype.UUID{
|
||||
"example_key": database.MustToDBUUID((*params.Fields)["example_key"]),
|
||||
Fields: &map[string]uuid.UUID{
|
||||
"example_key": (*params.Fields)["example_key"],
|
||||
},
|
||||
}, dbparams)
|
||||
|
||||
@@ -191,38 +189,38 @@ func TestSubmitSet(t *testing.T) {
|
||||
}
|
||||
aV := int32(2)
|
||||
params := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(current.ClientID),
|
||||
ClientID: current.ClientID,
|
||||
ActiveVersion: &aV,
|
||||
MinCleanVersion: &minCleanV,
|
||||
MinTextVersion: &minTextV,
|
||||
Fields: &map[string]pgtype.UUID{
|
||||
"example_key": database.MustToDBUUID(uuid.New()),
|
||||
"second_key": database.MustToDBUUID(uuid.New()),
|
||||
"changed_key": database.MustToDBUUID(current.Fields["original_key"]),
|
||||
"og_key": database.MustToDBUUID(current.Fields["og_key"]),
|
||||
Fields: &map[string]uuid.UUID{
|
||||
"example_key": uuid.New(),
|
||||
"second_key": uuid.New(),
|
||||
"changed_key": current.Fields["original_key"],
|
||||
"og_key": current.Fields["og_key"],
|
||||
},
|
||||
}
|
||||
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
rv := int32(2)
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(database.MustToDBUUID(current.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestCollectorVersion :one").WithArgs(current.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(rv),
|
||||
)
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(2)).
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(current.ClientID, int32(2)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *params.MinCleanVersion).
|
||||
pool.ExpectExec("name: SetCollectorCleanVersion :exec").WithArgs(current.ClientID, rv, *params.MinCleanVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: SetCollectorTextVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), rv, *params.MinTextVersion).
|
||||
pool.ExpectExec("name: SetCollectorTextVersion :exec").WithArgs(current.ClientID, rv, *params.MinTextVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: RemoveCollectorQuery :exec").WithArgs(&rv, database.MustToDBUUID(current.Fields["original_key"]), database.MustToDBUUID(current.ClientID)).
|
||||
pool.ExpectExec("name: RemoveCollectorQuery :exec").WithArgs(&rv, current.Fields["original_key"], current.ClientID).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.MatchExpectationsInOrder(false)
|
||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(current.ClientID), "example_key", (*params.Fields)["example_key"], int32(2)).
|
||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(current.ClientID, "example_key", (*params.Fields)["example_key"], int32(2)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(current.ClientID), "second_key", (*params.Fields)["second_key"], int32(2)).
|
||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(current.ClientID, "second_key", (*params.Fields)["second_key"], int32(2)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(database.MustToDBUUID(current.ClientID), "changed_key", (*params.Fields)["changed_key"], int32(2)).
|
||||
pool.ExpectExec("name: AddCollectorQuery :exec").WithArgs(current.ClientID, "changed_key", (*params.Fields)["changed_key"], int32(2)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -254,12 +252,12 @@ func TestSubmitSet(t *testing.T) {
|
||||
}
|
||||
av := int32(2)
|
||||
params := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(current.ClientID),
|
||||
ClientID: current.ClientID,
|
||||
ActiveVersion: &av,
|
||||
}
|
||||
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(database.MustToDBUUID(current.ClientID), int32(2)).
|
||||
pool.ExpectExec("name: SetActiveCollectorVersion :exec").WithArgs(current.ClientID, int32(2)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -443,7 +441,7 @@ func TestNormalizeCodeVersions(t *testing.T) {
|
||||
|
||||
func TestGetRemoveFields(t *testing.T) {
|
||||
current := map[string]uuid.UUID{}
|
||||
var update *map[string]pgtype.UUID
|
||||
var update *map[string]uuid.UUID
|
||||
|
||||
remove := getRemoveFields(current, update)
|
||||
assert.Len(t, remove, 0)
|
||||
@@ -452,29 +450,29 @@ func TestGetRemoveFields(t *testing.T) {
|
||||
remove = getRemoveFields(current, update)
|
||||
assert.Len(t, remove, 0)
|
||||
|
||||
update = &map[string]pgtype.UUID{
|
||||
"b": database.MustToDBUUID(uuid.New()),
|
||||
update = &map[string]uuid.UUID{
|
||||
"b": uuid.New(),
|
||||
}
|
||||
|
||||
(*update)["a"] = database.MustToDBUUID(current["a"])
|
||||
(*update)["a"] = current["a"]
|
||||
remove = getRemoveFields(current, update)
|
||||
assert.Len(t, remove, 0)
|
||||
|
||||
(*update)["a"] = database.MustToDBUUID(uuid.New())
|
||||
(*update)["a"] = uuid.New()
|
||||
remove = getRemoveFields(current, update)
|
||||
assert.Len(t, remove, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{database.MustToDBUUID(current["a"])}, remove)
|
||||
assert.ElementsMatch(t, []uuid.UUID{current["a"]}, remove)
|
||||
|
||||
(*update)["a"] = database.MustToDBUUID(uuid.Nil)
|
||||
(*update)["c"] = database.MustToDBUUID(current["a"])
|
||||
(*update)["a"] = uuid.Nil
|
||||
(*update)["c"] = current["a"]
|
||||
remove = getRemoveFields(current, update)
|
||||
assert.Len(t, remove, 1)
|
||||
assert.ElementsMatch(t, []pgtype.UUID{database.MustToDBUUID(current["a"])}, remove)
|
||||
assert.ElementsMatch(t, []uuid.UUID{current["a"]}, remove)
|
||||
}
|
||||
|
||||
func TestGetAddFields(t *testing.T) {
|
||||
current := map[string]uuid.UUID{}
|
||||
var update *map[string]pgtype.UUID
|
||||
var update *map[string]uuid.UUID
|
||||
|
||||
add := getAddFields(current, update)
|
||||
assert.Len(t, add, 0)
|
||||
@@ -483,34 +481,34 @@ func TestGetAddFields(t *testing.T) {
|
||||
add = getAddFields(current, update)
|
||||
assert.Len(t, add, 0)
|
||||
|
||||
update = &map[string]pgtype.UUID{}
|
||||
update = &map[string]uuid.UUID{}
|
||||
|
||||
add = getAddFields(current, update)
|
||||
assert.Len(t, add, 0)
|
||||
|
||||
(*update)["a"] = database.MustToDBUUID(current["a"])
|
||||
(*update)["a"] = current["a"]
|
||||
add = getAddFields(current, update)
|
||||
assert.Len(t, add, 0)
|
||||
|
||||
(*update)["a"] = database.MustToDBUUID(uuid.New())
|
||||
(*update)["a"] = uuid.New()
|
||||
add = getAddFields(current, update)
|
||||
assert.Len(t, add, 1)
|
||||
assert.Equal(t, map[string]pgtype.UUID{
|
||||
assert.Equal(t, map[string]uuid.UUID{
|
||||
"a": (*update)["a"],
|
||||
}, add)
|
||||
|
||||
(*update)["a"] = database.MustToDBUUID(current["a"])
|
||||
(*update)["b"] = database.MustToDBUUID(uuid.New())
|
||||
(*update)["a"] = current["a"]
|
||||
(*update)["b"] = uuid.New()
|
||||
add = getAddFields(current, update)
|
||||
assert.Len(t, add, 1)
|
||||
assert.Equal(t, map[string]pgtype.UUID{
|
||||
assert.Equal(t, map[string]uuid.UUID{
|
||||
"b": (*update)["b"],
|
||||
}, add)
|
||||
|
||||
current = map[string]uuid.UUID{}
|
||||
add = getAddFields(current, update)
|
||||
assert.Len(t, add, 2)
|
||||
assert.Equal(t, map[string]pgtype.UUID{
|
||||
assert.Equal(t, map[string]uuid.UUID{
|
||||
"b": (*update)["b"],
|
||||
"a": (*update)["a"],
|
||||
}, add)
|
||||
@@ -539,15 +537,15 @@ func TestNormalizeSetFieldsToDB(t *testing.T) {
|
||||
"example_key": uuid.New(),
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs([]uuid.UUID{fields["example_key"]}).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
AddRow(true),
|
||||
)
|
||||
|
||||
dbparams, err := svc.normalizeSetFieldsToDB(ctx, current, &fields)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &map[string]pgtype.UUID{
|
||||
"example_key": database.MustToDBUUID(fields["example_key"]),
|
||||
assert.EqualExportedValues(t, &map[string]uuid.UUID{
|
||||
"example_key": fields["example_key"],
|
||||
}, dbparams)
|
||||
})
|
||||
|
||||
@@ -571,7 +569,7 @@ func TestNormalizeSetFieldsToDB(t *testing.T) {
|
||||
}
|
||||
fields["second_key"] = fields["example_key"]
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs([]uuid.UUID{fields["example_key"]}).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
AddRow(true),
|
||||
)
|
||||
@@ -620,7 +618,7 @@ func TestInformSet(t *testing.T) {
|
||||
|
||||
av := int32(2)
|
||||
update := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(uuid.New()),
|
||||
ClientID: uuid.New(),
|
||||
ActiveVersion: &av,
|
||||
}
|
||||
|
||||
@@ -652,7 +650,7 @@ func TestInformSet(t *testing.T) {
|
||||
svc := New(cfg, &Services{})
|
||||
|
||||
update := dbSetParams{
|
||||
ClientID: database.MustToDBUUID(uuid.New()),
|
||||
ClientID: uuid.New(),
|
||||
}
|
||||
|
||||
err = svc.informSet(ctx, &update)
|
||||
@@ -678,20 +676,20 @@ func TestNormalizeFieldsToDB(t *testing.T) {
|
||||
"example_key": uuid.New(),
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs([]uuid.UUID{fields["example_key"]}).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
AddRow(true),
|
||||
)
|
||||
|
||||
dbparams, err := svc.normalizeFieldsToDB(ctx, &fields)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &map[string]pgtype.UUID{
|
||||
"example_key": database.MustToDBUUID(fields["example_key"]),
|
||||
assert.EqualExportedValues(t, &map[string]uuid.UUID{
|
||||
"example_key": fields["example_key"],
|
||||
}, dbparams)
|
||||
|
||||
fields["second_key"] = fields["example_key"]
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray([]uuid.UUID{fields["example_key"]})).WillReturnRows(
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs([]uuid.UUID{fields["example_key"]}).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
AddRow(true),
|
||||
)
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig/build"
|
||||
@@ -88,7 +87,7 @@ func (s *Service) executeCleanTasks(ctx context.Context, params *CleanParams) (*
|
||||
|
||||
func (s *Service) clean(ctx context.Context, id uuid.UUID) error {
|
||||
slog.Debug("cleaning document", "id", id.String())
|
||||
docId := database.MustToDBUUID(id)
|
||||
docId := id
|
||||
|
||||
doc, err := s.cfg.GetDBQueries().GetDocumentSummary(ctx, docId)
|
||||
if err != nil {
|
||||
@@ -121,7 +120,7 @@ func (s *Service) clean(ctx context.Context, id uuid.UUID) error {
|
||||
}
|
||||
|
||||
func (s *Service) storeClean(ctx context.Context, id uuid.UUID, out *ExecuteCleanResponse) error {
|
||||
docId := database.MustToDBUUID(id)
|
||||
docId := id
|
||||
version := build.GetVersionUnixTimestamp()
|
||||
|
||||
params := &repository.AddDocumentCleanParams{
|
||||
@@ -174,7 +173,7 @@ func (s *Service) storeClean(ctx context.Context, id uuid.UUID, out *ExecuteClea
|
||||
}
|
||||
|
||||
func (s *Service) isNewClean(lastEntry *repository.GetMostRecentDocumentCleanEntryRow, out *ExecuteCleanResponse) bool {
|
||||
if lastEntry == nil || !lastEntry.ID.Valid {
|
||||
if lastEntry == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -186,6 +185,10 @@ func (s *Service) isNewClean(lastEntry *repository.GetMostRecentDocumentCleanEnt
|
||||
return true
|
||||
}
|
||||
|
||||
if out.location == nil || out.mimetype == nil || lastEntry.Bucket == nil || lastEntry.Key == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return !(out.location.Bucket == *lastEntry.Bucket &&
|
||||
out.location.Key == *lastEntry.Key &&
|
||||
*out.mimetype == ParseDBNullMimeType(lastEntry.Mimetype))
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
objectstoremock "queryorchestration/mocks/objectstore"
|
||||
@@ -44,12 +43,12 @@ func TestClean(t *testing.T) {
|
||||
Bucket: "bucket_name",
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
dbid := doc.ID
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(dbid).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
||||
AddRow(dbid, database.MustToDBUUID(doc.ClientID), doc.Hash),
|
||||
AddRow(dbid, doc.ClientID, doc.Hash),
|
||||
)
|
||||
pool.ExpectQuery("name: GetDocumentEntry :one").WithArgs(dbid).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
|
||||
@@ -65,7 +64,7 @@ func TestClean(t *testing.T) {
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}),
|
||||
)
|
||||
cleanid := database.MustToDBUUID(uuid.New())
|
||||
cleanid := uuid.New()
|
||||
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
@@ -186,7 +185,7 @@ func TestStoreClean(t *testing.T) {
|
||||
location: &inloc,
|
||||
mimetype: (*MimeType)(&mimeType),
|
||||
}
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
dbid := doc.ID
|
||||
|
||||
dbmimetype := repository.NullCleanmimetype{
|
||||
Valid: true,
|
||||
@@ -197,7 +196,7 @@ func TestStoreClean(t *testing.T) {
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}),
|
||||
)
|
||||
cleanid := database.MustToDBUUID(uuid.New())
|
||||
cleanid := uuid.New()
|
||||
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
@@ -216,7 +215,7 @@ func TestStoreClean(t *testing.T) {
|
||||
location: &inloc,
|
||||
mimetype: (*MimeType)(&mimeType),
|
||||
}
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
dbid := doc.ID
|
||||
|
||||
dbmimetype := repository.NullCleanmimetype{
|
||||
Valid: true,
|
||||
@@ -226,9 +225,9 @@ func TestStoreClean(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(database.MustToDBUUID(uuid.New()), dbid, nil, nil, int64(1), nil, repository.CleanfailtypeInvalidRead),
|
||||
AddRow(uuid.New(), dbid, nil, nil, int64(1), nil, repository.CleanfailtypeInvalidRead),
|
||||
)
|
||||
cleanid := database.MustToDBUUID(uuid.New())
|
||||
cleanid := uuid.New()
|
||||
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
@@ -246,8 +245,8 @@ func TestStoreClean(t *testing.T) {
|
||||
params := &ExecuteCleanResponse{
|
||||
failReason: &reason,
|
||||
}
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
cleanid := database.MustToDBUUID(uuid.New())
|
||||
dbid := doc.ID
|
||||
cleanid := uuid.New()
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: GetMostRecentDocumentCleanEntry :one").WithArgs(dbid).
|
||||
@@ -276,7 +275,7 @@ func TestIsNewClean(t *testing.T) {
|
||||
})
|
||||
t.Run("same fail", func(t *testing.T) {
|
||||
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Fail: repository.NullCleanfailtype{
|
||||
Valid: true,
|
||||
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
||||
@@ -290,7 +289,7 @@ func TestIsNewClean(t *testing.T) {
|
||||
})
|
||||
t.Run("different fail", func(t *testing.T) {
|
||||
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Fail: repository.NullCleanfailtype{
|
||||
Valid: true,
|
||||
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
||||
@@ -309,7 +308,7 @@ func TestIsNewClean(t *testing.T) {
|
||||
}
|
||||
mimeType := MimeTypePDF
|
||||
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Bucket: &loc.Bucket,
|
||||
Key: &loc.Key,
|
||||
Mimetype: repository.NullCleanmimetype{
|
||||
@@ -334,7 +333,7 @@ func TestIsNewClean(t *testing.T) {
|
||||
}
|
||||
mimeType := MimeTypePDF
|
||||
var lastEntry *repository.GetMostRecentDocumentCleanEntryRow = &repository.GetMostRecentDocumentCleanEntryRow{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Bucket: &ogloc.Bucket,
|
||||
Key: &ogloc.Key,
|
||||
Mimetype: repository.NullCleanmimetype{
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
"context"
|
||||
|
||||
doctextrunner "queryorchestration/api/docTextRunner"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) Clean(ctx context.Context, id uuid.UUID) error {
|
||||
isclean, err := s.cfg.GetDBQueries().HasDocumentCleanEntry(ctx, database.MustToDBUUID(id))
|
||||
isclean, err := s.cfg.GetDBQueries().HasDocumentCleanEntry(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -58,7 +57,7 @@ func TestCreate(t *testing.T) {
|
||||
Bucket: "bucket_name",
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
dbid := doc.ID
|
||||
|
||||
pool.ExpectQuery("name: HasDocumentCleanEntry :one").WithArgs(dbid).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"isclean"}).
|
||||
@@ -67,7 +66,7 @@ func TestCreate(t *testing.T) {
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(dbid).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
||||
AddRow(dbid, database.MustToDBUUID(doc.ClientID), doc.Hash),
|
||||
AddRow(dbid, doc.ClientID, doc.Hash),
|
||||
)
|
||||
pool.ExpectQuery("name: GetDocumentEntry :one").WithArgs(dbid).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"documentId", "bucket", "key"}).
|
||||
@@ -83,7 +82,7 @@ func TestCreate(t *testing.T) {
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}),
|
||||
)
|
||||
cleanid := database.MustToDBUUID(uuid.New())
|
||||
cleanid := uuid.New()
|
||||
pool.ExpectQuery("name: AddDocumentClean :one").WithArgs(dbid, &inloc.Bucket, &inloc.Key, dbmimetype, repository.NullCleanfailtype{}).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
|
||||
@@ -4,26 +4,24 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) GetSummary(ctx context.Context, id uuid.UUID) (*DocumentSummary, error) {
|
||||
doc, err := s.cfg.GetDBQueries().GetDocumentSummary(ctx, database.MustToDBUUID(id))
|
||||
doc, err := s.cfg.GetDBQueries().GetDocumentSummary(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DocumentSummary{
|
||||
ID: database.MustToUUID(doc.ID),
|
||||
ClientID: database.MustToUUID(doc.Clientid),
|
||||
ID: doc.ID,
|
||||
ClientID: doc.Clientid,
|
||||
Hash: doc.Hash,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetExternal(ctx context.Context, id uuid.UUID) (*DocumentExternal, error) {
|
||||
doc, err := s.cfg.GetDBQueries().GetDocumentExternal(ctx, database.MustToDBUUID(id))
|
||||
doc, err := s.cfg.GetDBQueries().GetDocumentExternal(ctx, &id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -35,7 +33,7 @@ func (s *Service) GetExternal(ctx context.Context, id uuid.UUID) (*DocumentExter
|
||||
}
|
||||
|
||||
return &DocumentExternal{
|
||||
Id: database.MustToUUID(doc.ID),
|
||||
Id: doc.ID,
|
||||
ClientID: doc.Clientid,
|
||||
Hash: doc.Hash,
|
||||
Fields: fields,
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -33,10 +32,10 @@ func TestGetSummary(t *testing.T) {
|
||||
Hash: "example_hash",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(doc.ID)).
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(doc.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.ClientID), doc.Hash),
|
||||
AddRow(doc.ID, doc.ClientID, doc.Hash),
|
||||
)
|
||||
|
||||
adoc, err := svc.GetSummary(ctx, doc.ID)
|
||||
@@ -64,10 +63,10 @@ func TestGetExternal(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentExternal :one").WithArgs(database.MustToDBUUID(doc.Id)).
|
||||
pool.ExpectQuery("name: GetDocumentExternal :one").WithArgs(&doc.Id).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "hash", "fields"}).
|
||||
AddRow(database.MustToDBUUID(doc.Id), "externalID", "example", []byte(`{"json": "hello"}`)),
|
||||
AddRow(doc.Id, "externalID", "example", []byte(`{"json": "hello"}`)),
|
||||
)
|
||||
|
||||
adoc, err := svc.GetExternal(ctx, doc.Id)
|
||||
|
||||
@@ -9,13 +9,11 @@ import (
|
||||
"regexp"
|
||||
|
||||
docsyncrunner "queryorchestration/api/docSyncRunner"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Create struct {
|
||||
@@ -52,18 +50,18 @@ func (s *Service) Create(ctx context.Context, doc *Create) (uuid.UUID, error) {
|
||||
}
|
||||
|
||||
type createDocumentParams struct {
|
||||
ID *pgtype.UUID
|
||||
ClientID pgtype.UUID
|
||||
ID *uuid.UUID
|
||||
ClientID uuid.UUID
|
||||
Hash string
|
||||
Location document.Location
|
||||
}
|
||||
|
||||
func (s *Service) getCreateParams(ctx context.Context, doc *Create) (*createDocumentParams, error) {
|
||||
idbyhash, err := s.cfg.GetDBQueries().GetDocumentIDByHash(ctx, &repository.GetDocumentIDByHashParams{
|
||||
Clientid: database.MustToDBUUID(doc.ClientID),
|
||||
Clientid: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
var docID *pgtype.UUID
|
||||
var docID *uuid.UUID
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, err
|
||||
} else if err == nil {
|
||||
@@ -72,7 +70,7 @@ func (s *Service) getCreateParams(ctx context.Context, doc *Create) (*createDocu
|
||||
|
||||
return &createDocumentParams{
|
||||
ID: docID,
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: doc.Location,
|
||||
}, nil
|
||||
@@ -82,7 +80,7 @@ func (s *Service) submitCreate(ctx context.Context, params *createDocumentParams
|
||||
var id uuid.UUID
|
||||
|
||||
err := s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
var dbid pgtype.UUID
|
||||
var dbid uuid.UUID
|
||||
if params.ID == nil {
|
||||
createid, err := s.cfg.GetDBQueries().CreateDocument(ctx, &repository.CreateDocumentParams{
|
||||
Clientid: params.ClientID,
|
||||
@@ -109,7 +107,7 @@ func (s *Service) submitCreate(ctx context.Context, params *createDocumentParams
|
||||
return err
|
||||
}
|
||||
|
||||
id = database.MustToUUID(dbid)
|
||||
id = dbid
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
@@ -45,30 +44,30 @@ func TestCreate(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}),
|
||||
)
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(database.MustToDBUUID(doc.ClientID), doc.Hash).
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(doc.ClientID, doc.Hash).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID)),
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(doc.ID), location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(doc.ID)).
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(doc.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.ClientID), doc.Hash),
|
||||
AddRow(doc.ID, doc.ClientID, doc.Hash),
|
||||
)
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(clientId)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(clientId), database.MustToDBUUID(clientId), true),
|
||||
AddRow(clientId, clientId, true),
|
||||
)
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(clientId)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(clientId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(clientId), "client_name", true),
|
||||
AddRow(clientId, "client_name", true),
|
||||
)
|
||||
|
||||
mockSQS.EXPECT().
|
||||
@@ -110,7 +109,7 @@ func TestGetCreateParams(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}),
|
||||
)
|
||||
|
||||
@@ -121,7 +120,7 @@ func TestGetCreateParams(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &createDocumentParams{
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: location,
|
||||
}, params)
|
||||
@@ -148,9 +147,9 @@ func TestGetCreateParamsExisting(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID)),
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
|
||||
params, err := svc.getCreateParams(ctx, &Create{
|
||||
@@ -159,10 +158,10 @@ func TestGetCreateParamsExisting(t *testing.T) {
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
dbid := database.MustToDBUUID(doc.ID)
|
||||
dbid := doc.ID
|
||||
assert.Equal(t, &createDocumentParams{
|
||||
ID: &dbid,
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Hash: doc.Hash,
|
||||
Location: location,
|
||||
}, params)
|
||||
@@ -188,7 +187,7 @@ func TestGetCreateParamsCurrentDocErr(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, database.MustToDBUUID(doc.ClientID)).
|
||||
pool.ExpectQuery("name: GetDocumentIDByHash :one").WithArgs(doc.Hash, doc.ClientID).
|
||||
WillReturnError(errors.New("db err"))
|
||||
|
||||
_, err = svc.getCreateParams(ctx, &Create{
|
||||
@@ -220,17 +219,17 @@ func TestSubmitCreate(t *testing.T) {
|
||||
}
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(database.MustToDBUUID(doc.ClientID), doc.Hash).
|
||||
pool.ExpectQuery("name: CreateDocument :one").WithArgs(doc.ClientID, doc.Hash).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID)),
|
||||
AddRow(doc.ID),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(doc.ID), location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
id, err := svc.submitCreate(ctx, &createDocumentParams{
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
@@ -260,14 +259,14 @@ func TestSubmitCreateExists(t *testing.T) {
|
||||
}
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(database.MustToDBUUID(doc.ID), location.Bucket, location.Key).
|
||||
pool.ExpectExec("name: AddDocumentEntry :exec").WithArgs(doc.ID, location.Bucket, location.Key).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
docid := database.MustToDBUUID(doc.ID)
|
||||
docid := doc.ID
|
||||
id, err := svc.submitCreate(ctx, &createDocumentParams{
|
||||
ID: &docid,
|
||||
ClientID: database.MustToDBUUID(doc.ClientID),
|
||||
ClientID: doc.ClientID,
|
||||
Location: location,
|
||||
Hash: doc.Hash,
|
||||
})
|
||||
|
||||
@@ -2,8 +2,6 @@ package document
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
)
|
||||
|
||||
func (s *Service) ListByClientExternalId(ctx context.Context, id string) ([]*DocumentSummary, error) {
|
||||
@@ -15,7 +13,7 @@ func (s *Service) ListByClientExternalId(ctx context.Context, id string) ([]*Doc
|
||||
docs := make([]*DocumentSummary, len(documents))
|
||||
for i, doc := range documents {
|
||||
docs[i] = &DocumentSummary{
|
||||
ID: database.MustToUUID(doc.ID),
|
||||
ID: doc.ID,
|
||||
Hash: doc.Hash,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -37,7 +36,7 @@ func TestListByClientId(t *testing.T) {
|
||||
pool.ExpectQuery("name: ListDocumentsByClientExternalId :many").WithArgs(clientId).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "hash"}).
|
||||
AddRow(database.MustToDBUUID(doc[0].ID), doc[0].Hash),
|
||||
AddRow(doc[0].ID, doc[0].Hash),
|
||||
)
|
||||
|
||||
adoc, err := svc.ListByClientExternalId(ctx, clientId)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
documentsync "queryorchestration/internal/document/sync"
|
||||
@@ -47,14 +46,14 @@ func TestSync(t *testing.T) {
|
||||
Hash: "example_hash",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(database.MustToDBUUID(doc.ID)).
|
||||
pool.ExpectQuery("name: GetDocumentSummary :one").WithArgs(doc.ID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "clientId", "hash"}).
|
||||
AddRow(database.MustToDBUUID(doc.ID), database.MustToDBUUID(doc.ClientID), doc.Hash),
|
||||
AddRow(doc.ID, doc.ClientID, doc.Hash),
|
||||
)
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(database.MustToDBUUID(j.ID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetClient :one").WithArgs(j.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "externalId", "name", "canSync"}).
|
||||
AddRow(database.MustToDBUUID(j.ID), "id", "client_name", true),
|
||||
AddRow(j.ID, "id", "client_name", true),
|
||||
)
|
||||
|
||||
mockSQS.EXPECT().
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"log/slog"
|
||||
|
||||
querysyncrunner "queryorchestration/api/querySyncRunner"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig/queue"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -14,13 +13,13 @@ import (
|
||||
func (s *Service) Extract(ctx context.Context, id uuid.UUID) error {
|
||||
slog.Debug("extracting document text", "id", id.String())
|
||||
|
||||
isextracted, err := s.cfg.GetDBQueries().IsDocumentTextExtracted(ctx, database.MustToDBUUID(id))
|
||||
isextracted, err := s.cfg.GetDBQueries().IsDocumentTextExtracted(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !isextracted {
|
||||
entry, err := s.cfg.GetDBQueries().GetCleanEntryByDocId(ctx, database.MustToDBUUID(id))
|
||||
entry, err := s.cfg.GetDBQueries().GetCleanEntryByDocId(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if entry.Fail.Valid {
|
||||
@@ -28,7 +27,7 @@ func (s *Service) Extract(ctx context.Context, id uuid.UUID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = s.extract(ctx, database.MustToUUID(entry.ID))
|
||||
err = s.extract(ctx, entry.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/queue/querysync"
|
||||
"queryorchestration/internal/serviceconfig/textract"
|
||||
queuemock "queryorchestration/mocks/queue"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
type DocTextConfig struct {
|
||||
serviceconfig.BaseConfig
|
||||
querysync.QuerySyncConfig
|
||||
textract.TextractConfig
|
||||
}
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
@@ -49,29 +50,37 @@ func TestCreate(t *testing.T) {
|
||||
Key: "/i/am/here",
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: IsDocumentTextExtracted :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
||||
pool.ExpectQuery("name: IsDocumentTextExtracted :one").WithArgs(id).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"isextracted"}).
|
||||
AddRow(false),
|
||||
)
|
||||
cleanId := database.MustToDBUUID(uuid.New())
|
||||
cleanId := uuid.New()
|
||||
mimeType := "application/pdf"
|
||||
dbmimetype := repository.NullCleanmimetype{
|
||||
Valid: true,
|
||||
Cleanmimetype: repository.Cleanmimetype(mimeType),
|
||||
}
|
||||
pool.ExpectQuery("name: GetCleanEntryByDocId :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetCleanEntryByDocId :one").WithArgs(id).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(cleanId, database.MustToDBUUID(id), &inloc.Bucket, &inloc.Key, int32(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
AddRow(cleanId, id, &inloc.Bucket, &inloc.Key, int32(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
)
|
||||
pool.ExpectQuery("name: GetCleanEntry :one").WithArgs(cleanId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(cleanId, database.MustToDBUUID(id), &inloc.Bucket, &inloc.Key, int32(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
AddRow(cleanId, id, &inloc.Bucket, &inloc.Key, int32(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
)
|
||||
pool.ExpectQuery("name: AddDocumentTextEntry :one").WithArgs(pgxmock.AnyArg(), inloc.Bucket, inloc.Key, cleanId).
|
||||
textId := uuid.New()
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: GetDocumentTextExtractionByHash :one").WithArgs(cleanId, "example").WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "cleanEntryId"}),
|
||||
)
|
||||
pool.ExpectQuery("name: AddDocumentText :one").WithArgs(inloc.Bucket, inloc.Key, cleanId, "example").
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(uuid.New())),
|
||||
AddRow(textId),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentTextEntry :exec").WithArgs(textId, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
mockSQS.EXPECT().
|
||||
SendMessage(
|
||||
@@ -93,12 +102,12 @@ func TestCreate(t *testing.T) {
|
||||
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: IsDocumentTextExtracted :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
||||
pool.ExpectQuery("name: IsDocumentTextExtracted :one").WithArgs(id).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"isextracted"}).AddRow(false),
|
||||
)
|
||||
pool.ExpectQuery("name: GetCleanEntryByDocId :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetCleanEntryByDocId :one").WithArgs(id).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(database.MustToDBUUID(id), database.MustToDBUUID(uuid.New()), nil, nil, int64(1), nil, fail),
|
||||
AddRow(id, uuid.New(), nil, nil, int64(1), nil, fail),
|
||||
)
|
||||
|
||||
err = svc.Extract(ctx, id)
|
||||
|
||||
@@ -2,9 +2,10 @@ package documenttext
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
"queryorchestration/internal/serviceconfig/build"
|
||||
@@ -12,37 +13,86 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (s *Service) executeExtraction(ctx context.Context, cleanId uuid.UUID) (*document.Location, error) {
|
||||
entry, err := s.cfg.GetDBQueries().GetCleanEntry(ctx, database.MustToDBUUID(cleanId))
|
||||
type extraction struct {
|
||||
TextLocation document.Location
|
||||
Hash string
|
||||
}
|
||||
|
||||
func (s *Service) executeExtraction(ctx context.Context, cleanId uuid.UUID) (*extraction, error) {
|
||||
entry, err := s.cfg.GetDBQueries().GetCleanEntry(ctx, cleanId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if entry.Fail.Valid {
|
||||
return nil, fmt.Errorf("no valid cleaning")
|
||||
}
|
||||
|
||||
return &document.Location{
|
||||
Bucket: *entry.Bucket,
|
||||
Key: *entry.Key,
|
||||
// analysis, detection - diff?
|
||||
// split page by page?
|
||||
// output format
|
||||
// index
|
||||
// pages
|
||||
// block types
|
||||
|
||||
return &extraction{
|
||||
Hash: "example",
|
||||
TextLocation: document.Location{
|
||||
Bucket: *entry.Bucket,
|
||||
Key: *entry.Key,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) extract(ctx context.Context, cleanId uuid.UUID) error {
|
||||
outLocation, err := s.executeExtraction(ctx, cleanId)
|
||||
details, err := s.executeExtraction(ctx, cleanId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
version := build.GetVersionUnixTimestamp()
|
||||
|
||||
_, err = s.cfg.GetDBQueries().AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: version,
|
||||
Bucket: outLocation.Bucket,
|
||||
Key: outLocation.Key,
|
||||
Cleanentryid: database.MustToDBUUID(cleanId),
|
||||
})
|
||||
err = s.storeExtraction(ctx, cleanId, details)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) storeExtraction(ctx context.Context, cleanId uuid.UUID, details *extraction) error {
|
||||
version := build.GetVersionUnixTimestamp()
|
||||
|
||||
return s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
existing, err := q.GetDocumentTextExtractionByHash(ctx, &repository.GetDocumentTextExtractionByHashParams{
|
||||
Hash: details.Hash,
|
||||
Cleanentryid: cleanId,
|
||||
})
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return err
|
||||
}
|
||||
|
||||
var textId uuid.UUID
|
||||
if existing == nil || errors.Is(err, sql.ErrNoRows) {
|
||||
newTextId, err := q.AddDocumentText(ctx, &repository.AddDocumentTextParams{
|
||||
Bucket: details.TextLocation.Bucket,
|
||||
Key: details.TextLocation.Key,
|
||||
Cleanentryid: cleanId,
|
||||
Hash: details.Hash,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
textId = newTextId
|
||||
} else {
|
||||
textId = existing.ID
|
||||
}
|
||||
|
||||
err = q.AddDocumentTextEntry(ctx, &repository.AddDocumentTextEntryParams{
|
||||
Version: version,
|
||||
Textid: textId,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/document"
|
||||
|
||||
@@ -36,7 +35,7 @@ func TestExtract(t *testing.T) {
|
||||
}
|
||||
|
||||
cleanId := uuid.New()
|
||||
dbCleanId := database.MustToDBUUID(cleanId)
|
||||
dbCleanId := cleanId
|
||||
mimeType := "application/pdf"
|
||||
dbmimetype := repository.NullCleanmimetype{
|
||||
Valid: true,
|
||||
@@ -44,13 +43,21 @@ func TestExtract(t *testing.T) {
|
||||
}
|
||||
pool.ExpectQuery("name: GetCleanEntry :one").WithArgs(dbCleanId).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(dbCleanId, database.MustToDBUUID(id), &inloc.Bucket, &inloc.Key, int64(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
AddRow(dbCleanId, id, &inloc.Bucket, &inloc.Key, int64(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
)
|
||||
pool.ExpectQuery("name: AddDocumentTextEntry :one").WithArgs(pgxmock.AnyArg(), inloc.Bucket, inloc.Key, dbCleanId).
|
||||
textId := uuid.New()
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: GetDocumentTextExtractionByHash :one").WithArgs(dbCleanId, "example").WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "cleanEntryId"}),
|
||||
)
|
||||
pool.ExpectQuery("name: AddDocumentText :one").WithArgs(inloc.Bucket, inloc.Key, dbCleanId, "example").
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(uuid.New())),
|
||||
AddRow(textId),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentTextEntry :exec").WithArgs(textId, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
err = svc.extract(ctx, cleanId)
|
||||
require.NoError(t, err)
|
||||
@@ -58,14 +65,14 @@ func TestExtract(t *testing.T) {
|
||||
t.Run("fail clean", func(t *testing.T) {
|
||||
id := uuid.New()
|
||||
|
||||
cleanId := database.MustToDBUUID(uuid.New())
|
||||
cleanId := uuid.New()
|
||||
fail := repository.NullCleanfailtype{
|
||||
Valid: true,
|
||||
Cleanfailtype: repository.CleanfailtypeInvalidMimetype,
|
||||
}
|
||||
pool.ExpectQuery("name: GetCleanEntry :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetCleanEntry :one").WithArgs(id).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(cleanId, database.MustToDBUUID(id), nil, nil, int64(1), nil, fail),
|
||||
AddRow(cleanId, id, nil, nil, int64(1), nil, fail),
|
||||
)
|
||||
|
||||
err = svc.extract(ctx, id)
|
||||
@@ -91,17 +98,65 @@ func TestExecuteExtraction(t *testing.T) {
|
||||
Bucket: "buck",
|
||||
Key: "key",
|
||||
}
|
||||
extract := extraction{
|
||||
TextLocation: location,
|
||||
Hash: "example",
|
||||
}
|
||||
dbmimetype := repository.NullCleanmimetype{
|
||||
Valid: true,
|
||||
Cleanmimetype: repository.CleanmimetypeApplicationPdf,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetCleanEntry :one").WithArgs(database.MustToDBUUID(id)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetCleanEntry :one").WithArgs(id).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "mimetype", "fail"}).
|
||||
AddRow(database.MustToDBUUID(uuid.New()), database.MustToDBUUID(id), &location.Bucket, &location.Key, int32(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
AddRow(uuid.New(), id, &location.Bucket, &location.Key, int32(1), dbmimetype, repository.NullCleanfailtype{}),
|
||||
)
|
||||
|
||||
outloc, err := svc.executeExtraction(ctx, id)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, location, *outloc)
|
||||
assert.EqualExportedValues(t, extract, *outloc)
|
||||
}
|
||||
|
||||
func TestStoreExtraction(t *testing.T) {
|
||||
pool, err := pgxmock.NewPool()
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := &DocTextConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := Service{
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
t.Run("not existing", func(t *testing.T) {
|
||||
cleanId := uuid.New()
|
||||
dbCleanId := cleanId
|
||||
textId := uuid.New()
|
||||
extract := extraction{
|
||||
TextLocation: document.Location{
|
||||
Bucket: "buck",
|
||||
Key: "key",
|
||||
},
|
||||
Hash: "example",
|
||||
}
|
||||
|
||||
pool.ExpectBegin()
|
||||
pool.ExpectQuery("name: GetDocumentTextExtractionByHash :one").WithArgs(dbCleanId, extract.Hash).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "documentId", "bucket", "key", "version", "hash", "cleanEntryId"}),
|
||||
)
|
||||
pool.ExpectQuery("name: AddDocumentText :one").WithArgs(extract.TextLocation.Bucket, extract.TextLocation.Key, dbCleanId, "example").
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(textId),
|
||||
)
|
||||
pool.ExpectExec("name: AddDocumentTextEntry :exec").WithArgs(textId, pgxmock.AnyArg()).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
err = svc.storeExtraction(ctx, cleanId, &extract)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package documenttext
|
||||
import (
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/queue/querysync"
|
||||
"queryorchestration/internal/serviceconfig/textract"
|
||||
)
|
||||
|
||||
type ConfigProvider interface {
|
||||
serviceconfig.ConfigProvider
|
||||
querysync.ConfigProvider
|
||||
textract.ConfigProvider
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
documenttext "queryorchestration/internal/document/text"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"queryorchestration/internal/serviceconfig/queue/querysync"
|
||||
"queryorchestration/internal/serviceconfig/textract"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
type DocTextConfig struct {
|
||||
serviceconfig.BaseConfig
|
||||
querysync.QuerySyncConfig
|
||||
textract.TextractConfig
|
||||
}
|
||||
|
||||
func TestService(t *testing.T) {
|
||||
|
||||
@@ -4,14 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
contextfull "queryorchestration/internal/query/types/contextFull"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func (s *Service) Create(ctx context.Context, entity *resultprocessor.Create) (uuid.UUID, error) {
|
||||
@@ -58,20 +56,20 @@ func (s *Service) submitCreate(ctx context.Context, entity *resultprocessor.Crea
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
var dbID pgtype.UUID
|
||||
var id uuid.UUID
|
||||
err = s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, qtx *repository.Queries) error {
|
||||
dbID, err = qtx.CreateQuery(ctx, query.Type)
|
||||
id, err = qtx.CreateQuery(ctx, query.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
version, err := qtx.AddLatestQueryVersion(ctx, dbID)
|
||||
version, err := qtx.AddLatestQueryVersion(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = qtx.AddActiveQueryVersion(ctx, &repository.AddActiveQueryVersionParams{
|
||||
Queryid: dbID,
|
||||
Queryid: id,
|
||||
Versionid: version,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -81,7 +79,7 @@ func (s *Service) submitCreate(ctx context.Context, entity *resultprocessor.Crea
|
||||
if query.RequiredQueryIDs != nil {
|
||||
for _, reqQuery := range *query.RequiredQueryIDs {
|
||||
err = qtx.AddRequiredQuery(ctx, &repository.AddRequiredQueryParams{
|
||||
Queryid: dbID,
|
||||
Queryid: id,
|
||||
Requiredqueryid: reqQuery,
|
||||
Addedversion: version,
|
||||
})
|
||||
@@ -93,7 +91,7 @@ func (s *Service) submitCreate(ctx context.Context, entity *resultprocessor.Crea
|
||||
|
||||
if query.Config != nil {
|
||||
err = qtx.SetQueryConfig(ctx, &repository.SetQueryConfigParams{
|
||||
Queryid: dbID,
|
||||
Queryid: id,
|
||||
Config: *query.Config,
|
||||
Addedversion: version,
|
||||
})
|
||||
@@ -108,11 +106,6 @@ func (s *Service) submitCreate(ctx context.Context, entity *resultprocessor.Crea
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
id, err := database.ToUUID(dbID)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
|
||||
}
|
||||
@@ -130,7 +123,7 @@ func (s *Service) getCreator(qType resultprocessor.Type) (resultprocessor.Creato
|
||||
|
||||
type createQuery struct {
|
||||
Type repository.Querytype
|
||||
RequiredQueryIDs *[]pgtype.UUID
|
||||
RequiredQueryIDs *[]uuid.UUID
|
||||
Config *[]byte
|
||||
}
|
||||
|
||||
@@ -140,9 +133,9 @@ func parseCreateQuery(q *resultprocessor.Create) (*createQuery, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var reqIDs *[]pgtype.UUID
|
||||
var reqIDs *[]uuid.UUID
|
||||
if q.RequiredQueryIDs != nil {
|
||||
tIDs := database.MustToDBUUIDArray(*q.RequiredQueryIDs)
|
||||
tIDs := *q.RequiredQueryIDs
|
||||
reqIDs = &tIDs
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
@@ -47,26 +46,26 @@ func TestCreate(t *testing.T) {
|
||||
dbType, err := resultprocessor.ToDBQueryType(create.Type)
|
||||
require.NoError(t, err)
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(database.MustToDBUUIDArray(*create.RequiredQueryIDs)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(*create.RequiredQueryIDs).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).AddRow(true),
|
||||
)
|
||||
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
pool.ExpectQuery("name: CreateQuery :one").WithArgs(dbType).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(q.ID)),
|
||||
AddRow(q.ID),
|
||||
)
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(database.MustToDBUUID(q.ID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(q.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(int32(1)),
|
||||
)
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(database.MustToDBUUID(q.ID), int32(1)).
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(q.ID, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
for _, req := range *create.RequiredQueryIDs {
|
||||
pool.ExpectExec("name: AddRequiredQuery :exec").WithArgs(database.MustToDBUUID(q.ID), database.MustToDBUUID(req), int32(1)).
|
||||
pool.ExpectExec("name: AddRequiredQuery :exec").WithArgs(q.ID, req, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
}
|
||||
pool.ExpectExec("name: SetQueryConfig :exec").WithArgs(database.MustToDBUUID(q.ID), []byte(*create.Config), int32(1)).
|
||||
pool.ExpectExec("name: SetQueryConfig :exec").WithArgs(q.ID, []byte(*create.Config), int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -99,13 +98,13 @@ func TestCreateMinimal(t *testing.T) {
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
pool.ExpectQuery("name: CreateQuery :one").WithArgs(dbType).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(q.ID)),
|
||||
AddRow(q.ID),
|
||||
)
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(database.MustToDBUUID(q.ID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(q.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(int32(1)),
|
||||
)
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(database.MustToDBUUID(q.ID), int32(1)).
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(q.ID, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -51,7 +50,7 @@ func TestParseCreateQuery(t *testing.T) {
|
||||
|
||||
resultQuery, err := parseCreateQuery(cQuery)
|
||||
require.NoError(t, err)
|
||||
rQIDs := database.MustToDBUUIDArray(*cQuery.RequiredQueryIDs)
|
||||
rQIDs := *cQuery.RequiredQueryIDs
|
||||
qcfg := []byte(*cQuery.Config)
|
||||
assert.EqualExportedValues(t, createQuery{
|
||||
Type: repository.QuerytypeContextFull,
|
||||
@@ -105,19 +104,19 @@ func TestSubmitCreate(t *testing.T) {
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
pool.ExpectQuery("name: CreateQuery :one").WithArgs(dbType).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(q.ID)),
|
||||
AddRow(q.ID),
|
||||
)
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(database.MustToDBUUID(q.ID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(q.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(int32(1)),
|
||||
)
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(database.MustToDBUUID(q.ID), int32(1)).
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(q.ID, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
for _, req := range *create.RequiredQueryIDs {
|
||||
pool.ExpectExec("name: AddRequiredQuery :exec").WithArgs(database.MustToDBUUID(q.ID), database.MustToDBUUID(req), int32(1)).
|
||||
pool.ExpectExec("name: AddRequiredQuery :exec").WithArgs(q.ID, req, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
}
|
||||
pool.ExpectExec("name: SetQueryConfig :exec").WithArgs(database.MustToDBUUID(q.ID), []byte(*create.Config), int32(1)).
|
||||
pool.ExpectExec("name: SetQueryConfig :exec").WithArgs(q.ID, []byte(*create.Config), int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -150,13 +149,13 @@ func TestSubmitCreateNoReqsOrConfig(t *testing.T) {
|
||||
pool.ExpectBeginTx(pgx.TxOptions{})
|
||||
pool.ExpectQuery("name: CreateQuery :one").WithArgs(dbType).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id"}).
|
||||
AddRow(database.MustToDBUUID(q.ID)),
|
||||
AddRow(q.ID),
|
||||
)
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(database.MustToDBUUID(q.ID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: AddLatestQueryVersion :one").WithArgs(q.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"version"}).
|
||||
AddRow(int32(1)),
|
||||
)
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(database.MustToDBUUID(q.ID), int32(1)).
|
||||
pool.ExpectExec("name: AddActiveQueryVersion :exec").WithArgs(q.ID, int32(1)).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
pool.ExpectCommit()
|
||||
|
||||
@@ -181,7 +180,7 @@ func TestNormalizeCreate(t *testing.T) {
|
||||
RequiredQueryIDs: &[]uuid.UUID{},
|
||||
}
|
||||
|
||||
dbids := database.MustToDBUUIDArray(*create.RequiredQueryIDs)
|
||||
dbids := *create.RequiredQueryIDs
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(dbids).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
|
||||
@@ -3,7 +3,6 @@ package query
|
||||
import (
|
||||
"context"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
|
||||
@@ -21,7 +20,7 @@ type Query struct {
|
||||
|
||||
func (s *Service) GetWithVersion(ctx context.Context, id uuid.UUID, version int32) (*Query, error) {
|
||||
query, err := s.cfg.GetDBQueries().GetQueryWithVersion(ctx, &repository.GetQueryWithVersionParams{
|
||||
ID: database.MustToDBUUID(id),
|
||||
ID: &id,
|
||||
Version: &version,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -32,7 +31,7 @@ func (s *Service) GetWithVersion(ctx context.Context, id uuid.UUID, version int3
|
||||
}
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Query, error) {
|
||||
query, err := s.cfg.GetDBQueries().GetQuery(ctx, database.MustToDBUUID(id))
|
||||
query, err := s.cfg.GetDBQueries().GetQuery(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
@@ -38,11 +37,11 @@ func TestGet(t *testing.T) {
|
||||
Config: &config,
|
||||
}
|
||||
|
||||
dbReqIDs := database.MustToDBUUIDArray(*query.RequiredQueryIDs)
|
||||
dbReqIDs := *query.RequiredQueryIDs
|
||||
|
||||
pool.ExpectQuery("name: GetQuery :one").WithArgs(database.MustToDBUUID(query.ID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetQuery :one").WithArgs(query.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
||||
AddRow(database.MustToDBUUID(query.ID), repository.QuerytypeJsonExtractor, query.ActiveVersion, query.LatestVersion, []byte(config), dbReqIDs),
|
||||
AddRow(query.ID, repository.QuerytypeJsonExtractor, query.ActiveVersion, query.LatestVersion, []byte(config), dbReqIDs),
|
||||
)
|
||||
|
||||
returnQuery, err := svc.Get(ctx, query.ID)
|
||||
@@ -75,11 +74,11 @@ func TestGetWithVersion(t *testing.T) {
|
||||
|
||||
version := int32(2)
|
||||
|
||||
dbReqIDs := database.MustToDBUUIDArray(*query.RequiredQueryIDs)
|
||||
dbReqIDs := *query.RequiredQueryIDs
|
||||
|
||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(database.MustToDBUUID(query.ID), &version).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(&query.ID, &version).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
||||
AddRow(database.MustToDBUUID(query.ID), repository.QuerytypeJsonExtractor, query.ActiveVersion, query.LatestVersion, []byte(config), dbReqIDs),
|
||||
AddRow(query.ID, repository.QuerytypeJsonExtractor, query.ActiveVersion, query.LatestVersion, []byte(config), dbReqIDs),
|
||||
)
|
||||
|
||||
returnQuery, err := svc.GetWithVersion(ctx, query.ID, version)
|
||||
|
||||
@@ -3,8 +3,6 @@ package query
|
||||
import (
|
||||
"context"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -23,7 +21,7 @@ func (s *Service) List(ctx context.Context) ([]*Query, error) {
|
||||
}
|
||||
|
||||
func (s *Service) ListById(ctx context.Context, ids []uuid.UUID) ([]*Query, error) {
|
||||
dbQueries, err := s.cfg.GetDBQueries().ListQueriesById(ctx, database.MustToDBUUIDArray(ids))
|
||||
dbQueries, err := s.cfg.GetDBQueries().ListQueriesById(ctx, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -40,11 +38,11 @@ func TestList(t *testing.T) {
|
||||
Config: &config,
|
||||
}
|
||||
|
||||
dbReqIDs := database.MustToDBUUIDArray(*q.RequiredQueryIDs)
|
||||
dbReqIDs := *q.RequiredQueryIDs
|
||||
|
||||
pool.ExpectQuery("name: ListQueries :many").WithArgs().WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
||||
AddRow(database.MustToDBUUID(q.ID), repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
|
||||
AddRow(q.ID, repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
|
||||
)
|
||||
|
||||
resList, err := svc.List(ctx)
|
||||
@@ -75,11 +73,11 @@ func TestListById(t *testing.T) {
|
||||
Config: &config,
|
||||
}
|
||||
|
||||
dbReqIDs := database.MustToDBUUIDArray(*q.RequiredQueryIDs)
|
||||
dbReqIDs := *q.RequiredQueryIDs
|
||||
|
||||
pool.ExpectQuery("name: ListQueriesById :many").WithArgs([]pgtype.UUID{database.MustToDBUUID(q.ID)}).WillReturnRows(
|
||||
pool.ExpectQuery("name: ListQueriesById :many").WithArgs([]uuid.UUID{q.ID}).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
||||
AddRow(database.MustToDBUUID(q.ID), repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
|
||||
AddRow(q.ID, repository.QuerytypeJsonExtractor, q.ActiveVersion, q.LatestVersion, []byte(config), dbReqIDs),
|
||||
)
|
||||
|
||||
resList, err := svc.ListById(ctx, []uuid.UUID{q.ID})
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/validation"
|
||||
|
||||
@@ -72,7 +71,7 @@ func (s *Service) NormalizeQueryIDs(ctx context.Context, ids RequiredQueryIDs) e
|
||||
dedup := validation.DeduplicateArray(*ide)
|
||||
ids.SetRequiredQueryIDs(&dedup)
|
||||
|
||||
dbids := database.MustToDBUUIDArray(dedup)
|
||||
dbids := dedup
|
||||
|
||||
exist, err := s.cfg.GetDBQueries().AllQueriesExist(ctx, dbids)
|
||||
if err != nil {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
@@ -97,7 +96,7 @@ func TestNormalizeQueryIDs(t *testing.T) {
|
||||
|
||||
ids := []uuid.UUID{uuid.New()}
|
||||
entity.RequiredQueryIDs = &ids
|
||||
dbids := database.MustToDBUUIDArray(*entity.RequiredQueryIDs)
|
||||
dbids := *entity.RequiredQueryIDs
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(dbids).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
@@ -127,7 +126,7 @@ func TestNormalizeQueryIDs(t *testing.T) {
|
||||
singleid := uuid.New()
|
||||
entity.RequiredQueryIDs = &[]uuid.UUID{singleid, singleid}
|
||||
outids := []uuid.UUID{singleid}
|
||||
dbids = database.MustToDBUUIDArray(outids)
|
||||
dbids = outids
|
||||
|
||||
pool.ExpectQuery("name: AllQueriesExist :one").WithArgs(dbids).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"all_exist"}).
|
||||
|
||||
+7
-12
@@ -1,7 +1,6 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
|
||||
@@ -30,15 +29,6 @@ func ParseQuery(q *Query) *resultprocessor.Query {
|
||||
}
|
||||
|
||||
func ParseFullActiveQuery(q *repository.Fullactivequery) (*Query, error) {
|
||||
var reqQueryIDs *[]uuid.UUID
|
||||
if len(q.Requiredids) > 0 {
|
||||
rQ, err := database.ToUUIDArray(q.Requiredids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reqQueryIDs = &rQ
|
||||
}
|
||||
|
||||
qType, err := resultprocessor.ParseDBType(q.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -50,12 +40,17 @@ func ParseFullActiveQuery(q *repository.Fullactivequery) (*Query, error) {
|
||||
scfg = &s
|
||||
}
|
||||
|
||||
var reqIds *[]uuid.UUID
|
||||
if len(q.Requiredids) > 0 {
|
||||
reqIds = &q.Requiredids
|
||||
}
|
||||
|
||||
return &Query{
|
||||
ID: database.MustToUUID(q.ID),
|
||||
ID: q.ID,
|
||||
ActiveVersion: q.Activeversion,
|
||||
LatestVersion: q.Latestversion,
|
||||
Type: qType,
|
||||
RequiredQueryIDs: reqQueryIDs,
|
||||
RequiredQueryIDs: reqIds,
|
||||
Config: scfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -3,13 +3,11 @@ package query_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -39,12 +37,12 @@ func TestParseQuery(t *testing.T) {
|
||||
|
||||
func TestParseFullActiveQuery(t *testing.T) {
|
||||
q := &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: int32(1),
|
||||
Latestversion: int32(2),
|
||||
Requiredids: []pgtype.UUID{
|
||||
database.MustToDBUUID(uuid.New()),
|
||||
Requiredids: []uuid.UUID{
|
||||
uuid.New(),
|
||||
},
|
||||
Config: []byte("example"),
|
||||
}
|
||||
@@ -53,12 +51,12 @@ func TestParseFullActiveQuery(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
bcfg := string(q.Config)
|
||||
assert.EqualExportedValues(t, query.Query{
|
||||
ID: database.MustToUUID(q.ID),
|
||||
ID: q.ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
ActiveVersion: q.Activeversion,
|
||||
LatestVersion: q.Latestversion,
|
||||
RequiredQueryIDs: &[]uuid.UUID{
|
||||
database.MustToUUID(q.Requiredids[0]),
|
||||
q.Requiredids[0],
|
||||
},
|
||||
Config: &bcfg,
|
||||
}, *out)
|
||||
@@ -66,7 +64,7 @@ func TestParseFullActiveQuery(t *testing.T) {
|
||||
|
||||
func TestFullActiveQueryEmpty(t *testing.T) {
|
||||
dbQuery := &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: int32(1),
|
||||
Latestversion: int32(2),
|
||||
@@ -75,7 +73,7 @@ func TestFullActiveQueryEmpty(t *testing.T) {
|
||||
out, err := query.ParseFullActiveQuery(dbQuery)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, query.Query{
|
||||
ID: database.MustToUUID(dbQuery.ID),
|
||||
ID: dbQuery.ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
ActiveVersion: int32(1),
|
||||
LatestVersion: int32(2),
|
||||
@@ -84,7 +82,7 @@ func TestFullActiveQueryEmpty(t *testing.T) {
|
||||
|
||||
func TestFullActiveQueryWithNullUUID(t *testing.T) {
|
||||
dbQuery := &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: int32(1),
|
||||
Latestversion: int32(2),
|
||||
@@ -93,7 +91,7 @@ func TestFullActiveQueryWithNullUUID(t *testing.T) {
|
||||
out, err := query.ParseFullActiveQuery(dbQuery)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, query.Query{
|
||||
ID: database.MustToUUID(dbQuery.ID),
|
||||
ID: dbQuery.ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
ActiveVersion: int32(1),
|
||||
LatestVersion: int32(2),
|
||||
@@ -103,7 +101,7 @@ func TestFullActiveQueryWithNullUUID(t *testing.T) {
|
||||
func TestFullActiveQueryArray(t *testing.T) {
|
||||
dbQueries := []*repository.Fullactivequery{
|
||||
{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: int32(1),
|
||||
Latestversion: int32(2),
|
||||
@@ -114,7 +112,7 @@ func TestFullActiveQueryArray(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, []*query.Query{
|
||||
{
|
||||
ID: database.MustToUUID(dbQueries[0].ID),
|
||||
ID: dbQueries[0].ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
ActiveVersion: int32(1),
|
||||
LatestVersion: int32(2),
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
contextfull "queryorchestration/internal/query/types/contextFull"
|
||||
@@ -23,9 +22,9 @@ type GetValueWithVersionParams struct {
|
||||
|
||||
func (s *Service) GetValueWithVersion(ctx context.Context, params *GetValueWithVersionParams) (resultprocessor.Value, error) {
|
||||
res, err := s.cfg.GetDBQueries().GetResultValueWithVersion(ctx, &repository.GetResultValueWithVersionParams{
|
||||
Queryid: database.MustToDBUUID(params.QueryID),
|
||||
Queryid: ¶ms.QueryID,
|
||||
Queryversion: ¶ms.QueryVersion,
|
||||
Documentid: database.MustToDBUUID(params.DocumentID),
|
||||
Documentid: ¶ms.DocumentID,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -4,14 +4,12 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
jsonextractor "queryorchestration/internal/query/types/jsonExtractor"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -49,10 +47,10 @@ func TestGetValueWithVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
value := "exaple_value"
|
||||
pool.ExpectQuery("name: GetResultValueWithVersion :one").WithArgs(database.MustToDBUUID(params.QueryID), ¶ms.QueryVersion, database.MustToDBUUID(params.DocumentID)).
|
||||
pool.ExpectQuery("name: GetResultValueWithVersion :one").WithArgs(¶ms.QueryID, ¶ms.QueryVersion, ¶ms.DocumentID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "value"}).
|
||||
AddRow(pgtype.UUID{}, &value),
|
||||
AddRow(&uuid.UUID{}, &value),
|
||||
)
|
||||
|
||||
val, err := svc.GetValueWithVersion(ctx, params)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
contextfull "queryorchestration/internal/query/types/contextFull"
|
||||
@@ -70,8 +69,8 @@ func (s *Service) listRequiredValues(ctx context.Context, p *Process, query *res
|
||||
}
|
||||
|
||||
qResults, err := s.cfg.GetDBQueries().ListQueryRequirementValues(ctx, &repository.ListQueryRequirementValuesParams{
|
||||
Queryid: database.MustToDBUUID(p.QueryID),
|
||||
Documentid: database.MustToDBUUID(p.DocumentID),
|
||||
Queryid: &p.QueryID,
|
||||
Documentid: &p.DocumentID,
|
||||
Version: &p.QueryVersion,
|
||||
})
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/query"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
@@ -46,17 +45,17 @@ func TestProcess(t *testing.T) {
|
||||
QueryVersion: query.Version,
|
||||
}
|
||||
|
||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(database.MustToDBUUID(query.ID), &query.Version).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetQueryWithVersion :one").WithArgs(&query.ID, &query.Version).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "type", "activeVersion", "latestVersion", "config", "requiredIds"}).
|
||||
AddRow(database.MustToDBUUID(query.ID), repository.QuerytypeJsonExtractor, query.Version, query.Version, []byte(*query.Config), database.MustToDBUUIDArray(*query.RequiredQueryIDs)),
|
||||
AddRow(query.ID, repository.QuerytypeJsonExtractor, query.Version, query.Version, []byte(*query.Config), *query.RequiredQueryIDs),
|
||||
)
|
||||
strVal := `{"examplekey":"example_value"}`
|
||||
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(database.MustToDBUUID(query.ID), &query.Version, database.MustToDBUUID(params.DocumentID)).
|
||||
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(&query.ID, &query.Version, ¶ms.DocumentID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
||||
AddRow(database.MustToDBUUID(uuid.New()), database.MustToDBUUID(query.ID), repository.QuerytypeContextFull, &strVal),
|
||||
AddRow(&uuid.UUID{}, query.ID, repository.QuerytypeContextFull, &strVal),
|
||||
)
|
||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID)).WillReturnRows(
|
||||
pool.ExpectQuery("name: GetActiveQueryConfig :one").WithArgs(query.ID).WillReturnRows(
|
||||
pgxmock.NewRows([]string{"config"}).
|
||||
AddRow([]byte(qcfg)),
|
||||
)
|
||||
@@ -109,10 +108,10 @@ func TestListRequiredValue(t *testing.T) {
|
||||
|
||||
strVal := "axe_value"
|
||||
|
||||
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(database.MustToDBUUID(query.ID), &query.Version, database.MustToDBUUID(params.DocumentID)).
|
||||
pool.ExpectQuery("name: ListQueryRequirementValues :many").WithArgs(&query.ID, &query.Version, ¶ms.DocumentID).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "queryId", "type", "value"}).
|
||||
AddRow(database.MustToDBUUID(uuid.New()), database.MustToDBUUID((*query.RequiredQueryIDs)[0]), repository.QuerytypeJsonExtractor, &strVal),
|
||||
AddRow(&uuid.UUID{}, (*query.RequiredQueryIDs)[0], repository.QuerytypeJsonExtractor, &strVal),
|
||||
)
|
||||
|
||||
pr, err = svc.listRequiredValues(ctx, ¶ms, query)
|
||||
@@ -141,7 +140,7 @@ func TestParseQueryRequirementValueArray(t *testing.T) {
|
||||
exval := "exampleval"
|
||||
in := []*repository.ListQueryRequirementValuesRow{
|
||||
{
|
||||
Queryid: database.MustToDBUUID(uuid.New()),
|
||||
Queryid: uuid.New(),
|
||||
Value: &exval,
|
||||
Type: repository.QuerytypeJsonExtractor,
|
||||
},
|
||||
|
||||
@@ -3,7 +3,6 @@ package resultprocessor
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -67,22 +66,21 @@ func ToDBNullQueryType(t Type) (repository.NullQuerytype, error) {
|
||||
}
|
||||
|
||||
func ParseDBCollectorQuery(q *repository.Collectorquerydependencytree) (*Query, error) {
|
||||
var reqQueryIDs *[]uuid.UUID
|
||||
if len(q.Requiredids) > 0 {
|
||||
ids := database.MustToUUIDArray(q.Requiredids)
|
||||
reqQueryIDs = &ids
|
||||
}
|
||||
|
||||
qType, err := ParseDBType(q.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var reqIds *[]uuid.UUID
|
||||
if len(q.Requiredids) > 0 {
|
||||
reqIds = &q.Requiredids
|
||||
}
|
||||
|
||||
return &Query{
|
||||
ID: database.MustToUUID(q.Queryid),
|
||||
ID: *q.Queryid,
|
||||
Version: q.Queryversion,
|
||||
Type: qType,
|
||||
RequiredQueryIDs: reqQueryIDs,
|
||||
RequiredQueryIDs: reqIds,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -96,23 +94,22 @@ func ParseFullQuery(qs *repository.Fullactivequery) (*Query, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var rids *[]uuid.UUID
|
||||
if len(qs.Requiredids) > 0 {
|
||||
r := database.MustToUUIDArray(qs.Requiredids)
|
||||
rids = &r
|
||||
}
|
||||
|
||||
var cfg *string
|
||||
if qs.Config != nil {
|
||||
c := string(qs.Config)
|
||||
cfg = &c
|
||||
}
|
||||
|
||||
var reqIds *[]uuid.UUID
|
||||
if len(qs.Requiredids) > 0 {
|
||||
reqIds = &qs.Requiredids
|
||||
}
|
||||
|
||||
return &Query{
|
||||
ID: database.MustToUUID(qs.ID),
|
||||
ID: qs.ID,
|
||||
Type: qt,
|
||||
Version: qs.Activeversion,
|
||||
RequiredQueryIDs: rids,
|
||||
RequiredQueryIDs: reqIds,
|
||||
Config: cfg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -3,21 +3,19 @@ package resultprocessor_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
resultprocessor "queryorchestration/internal/query/result/processor"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseDBCollectorQuery(t *testing.T) {
|
||||
dbResult := repository.Collectorquerydependencytree{
|
||||
Clientid: pgtype.UUID{},
|
||||
Queryid: pgtype.UUID{},
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Clientid: uuid.UUID{},
|
||||
Queryid: &uuid.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
Type: repository.QuerytypeJsonExtractor,
|
||||
Queryversion: 1,
|
||||
}
|
||||
@@ -118,7 +116,7 @@ func TestParseFullQuery(t *testing.T) {
|
||||
assert.Nil(t, out)
|
||||
|
||||
q = &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: 1,
|
||||
Latestversion: 2,
|
||||
@@ -126,36 +124,36 @@ func TestParseFullQuery(t *testing.T) {
|
||||
|
||||
out, err = resultprocessor.ParseFullQuery(q)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &resultprocessor.Query{
|
||||
ID: database.MustToUUID(q.ID),
|
||||
assert.EqualExportedValues(t, resultprocessor.Query{
|
||||
ID: q.ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
Version: 1,
|
||||
}, out)
|
||||
}, *out)
|
||||
|
||||
q = &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: 1,
|
||||
Latestversion: 2,
|
||||
Requiredids: []pgtype.UUID{},
|
||||
Requiredids: []uuid.UUID{},
|
||||
}
|
||||
|
||||
out, err = resultprocessor.ParseFullQuery(q)
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, &resultprocessor.Query{
|
||||
ID: database.MustToUUID(q.ID),
|
||||
ID: q.ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
Version: 1,
|
||||
}, out)
|
||||
|
||||
q = &repository.Fullactivequery{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: 1,
|
||||
Latestversion: 2,
|
||||
Config: []byte("hello"),
|
||||
Requiredids: []pgtype.UUID{
|
||||
database.MustToDBUUID(uuid.New()),
|
||||
Requiredids: []uuid.UUID{
|
||||
uuid.New(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -163,11 +161,11 @@ func TestParseFullQuery(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
cfg := "hello"
|
||||
assert.EqualExportedValues(t, &resultprocessor.Query{
|
||||
ID: database.MustToUUID(q.ID),
|
||||
ID: q.ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
Version: 1,
|
||||
Config: &cfg,
|
||||
RequiredQueryIDs: &[]uuid.UUID{database.MustToUUID(q.Requiredids[0])},
|
||||
RequiredQueryIDs: &[]uuid.UUID{q.Requiredids[0]},
|
||||
}, out)
|
||||
}
|
||||
|
||||
@@ -179,7 +177,7 @@ func TestParseFullQueryArray(t *testing.T) {
|
||||
|
||||
q = []*repository.Fullactivequery{
|
||||
{
|
||||
ID: database.MustToDBUUID(uuid.New()),
|
||||
ID: uuid.New(),
|
||||
Type: repository.QuerytypeContextFull,
|
||||
Activeversion: 1,
|
||||
Latestversion: 2,
|
||||
@@ -190,7 +188,7 @@ func TestParseFullQueryArray(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.EqualExportedValues(t, []*resultprocessor.Query{
|
||||
{
|
||||
ID: database.MustToUUID(q[0].ID),
|
||||
ID: q[0].ID,
|
||||
Type: resultprocessor.TypeContextFull,
|
||||
Version: 1,
|
||||
},
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user