basestructure
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# https://taskfile.dev
|
||||
|
||||
version: '3'
|
||||
|
||||
includes:
|
||||
lib:
|
||||
taskfile: scripts/Taskfile.yml
|
||||
flatten: true
|
||||
vars:
|
||||
IMAGE_NAME: queryorchestration
|
||||
COVERAGE_THRESHOLD: 80
|
||||
@@ -10,10 +10,10 @@ SELECT EXISTS (
|
||||
);
|
||||
|
||||
-- name: GetQuery :one
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(DISTINCT r.requiredQueryId) as requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
WHERE q.id = $1
|
||||
and c.addedVersion >= q.activeVersion
|
||||
and COALESCE(c.removedVersion, q.activeVersion - 1) < q.activeVersion
|
||||
@@ -24,8 +24,8 @@ SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.req
|
||||
-- name: ListQueries :many
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
WHERE c.addedVersion >= q.activeVersion
|
||||
and COALESCE(c.removedVersion, q.activeVersion - 1) < q.activeVersion
|
||||
and r.addedVersion >= q.activeVersion
|
||||
|
||||
@@ -62,10 +62,10 @@ func (q *Queries) DeprecateQuery(ctx context.Context, queryid pgtype.UUID) error
|
||||
}
|
||||
|
||||
const getQuery = `-- name: GetQuery :one
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(DISTINCT r.requiredQueryId) as requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
WHERE q.id = $1
|
||||
and c.addedVersion >= q.activeVersion
|
||||
and COALESCE(c.removedVersion, q.activeVersion - 1) < q.activeVersion
|
||||
@@ -134,8 +134,8 @@ func (q *Queries) IsQueryDeprecated(ctx context.Context, queryid pgtype.UUID) (b
|
||||
const listQueries = `-- name: ListQueries :many
|
||||
SELECT q.id, q.type, q.activeVersion, q.latestVersion, c.config, ARRAY_AGG(r.requiredQueryId) AS requiredIds
|
||||
FROM queries AS q
|
||||
JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
LEFT JOIN queryConfigs AS c ON q.id = c.queryId
|
||||
LEFT JOIN requiredQueries AS r ON q.id = r.queryId
|
||||
WHERE c.addedVersion >= q.activeVersion
|
||||
and COALESCE(c.removedVersion, q.activeVersion - 1) < q.activeVersion
|
||||
and r.addedVersion >= q.activeVersion
|
||||
|
||||
@@ -42,7 +42,7 @@ func (s *Service) submitCreate(ctx context.Context, entity *queryprocessor.Creat
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
defer tx.Rollback(ctx)
|
||||
// defer tx.Rollback(ctx)
|
||||
|
||||
qtx := s.db.Queries.WithTx(tx)
|
||||
|
||||
@@ -73,6 +73,11 @@ func (s *Service) submitCreate(ctx context.Context, entity *queryprocessor.Creat
|
||||
}
|
||||
}
|
||||
|
||||
err = tx.Commit(ctx)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
id := database.MustToUUID(dbID)
|
||||
|
||||
return id, nil
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
func TestQueryRunner(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
queue, cleanup := createQueueDependencies(t, ctx, "queryrunner")
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQuery(t *testing.T) {
|
||||
func TestQueryService(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
conn, cleanup := createAPIDependencies(t, ctx, "queryservice")
|
||||
@@ -16,11 +16,32 @@ func TestQuery(t *testing.T) {
|
||||
|
||||
client := serviceinterfaces.NewQueryServiceClient(conn)
|
||||
|
||||
id := "sample_id"
|
||||
|
||||
_, err := client.Get(ctx, &serviceinterfaces.IdMessage{
|
||||
Id: id,
|
||||
config := ""
|
||||
reqQueries := []string{}
|
||||
idRes, err := client.Create(ctx, &serviceinterfaces.QueryCreate{
|
||||
Type: 1,
|
||||
Config: &config,
|
||||
RequiredQueries: reqQueries,
|
||||
})
|
||||
|
||||
assert.Nil(t, err)
|
||||
id := idRes.GetId()
|
||||
assert.NotEmpty(t, id)
|
||||
|
||||
// queryRes, err := client.Get(ctx, &serviceinterfaces.IdMessage{
|
||||
// Id: id,
|
||||
// })
|
||||
// log.Print(err)
|
||||
// assert.Nil(t, err)
|
||||
// assert.EqualExportedValues(t, serviceinterfaces.Query{
|
||||
// Id: id,
|
||||
// Type: serviceinterfaces.QueryType_QUERY_TYPE_CONTEXT_FULL,
|
||||
// ActiveVersion: int32(1),
|
||||
// LatestVersion: int32(1),
|
||||
// Config: &config,
|
||||
// RequiredQueries: reqQueries,
|
||||
// }, *queryRes)
|
||||
|
||||
//QueryService - List, Update, Test
|
||||
//JobController - Create, Update, Get
|
||||
//Export - Trigger
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package database_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestQueryTypeScan(t *testing.T) {
|
||||
qType := repository.Querytype(fmt.Sprint(0))
|
||||
|
||||
stringType := "context_full"
|
||||
err := qType.Scan(stringType)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestNullQueryTypeScan(t *testing.T) {
|
||||
qType := repository.NullQuerytype{}
|
||||
|
||||
stringType := "context_full"
|
||||
err := qType.Scan(stringType)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestNullQueryTypeValue(t *testing.T) {
|
||||
qType := repository.NullQuerytype{}
|
||||
|
||||
stringType := "context_full"
|
||||
err := qType.Scan(stringType)
|
||||
assert.Nil(t, err)
|
||||
|
||||
val, err := qType.Value()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, stringType, val)
|
||||
}
|
||||
Reference in New Issue
Block a user