diff --git a/Taskfile.yml b/Taskfile.yml index 3e31fbd1250e..dd10a5411d34 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -100,7 +100,7 @@ tasks: {{.SERVICES}} env-setup: - deps: [gen-version] + deps: [gen-version, build-envtool] cmds: - bin/envtool{{exeExt}} setup @@ -143,6 +143,7 @@ tasks: - go generate -x ./build/version build-envtool: + run: once cmds: - go build -v -o bin/ ./cmd/envtool/ @@ -151,6 +152,7 @@ tasks: run: once deps: [gen-version] cmds: + - echo 'build-host' > build/version/package.txt - go build -v -o=bin/ferretdb{{exeExt}} {{.RACE_FLAG}} -tags={{.BUILD_TAGS}} -coverpkg=./... ./cmd/ferretdb - bin/envtool{{exeExt}} shell mkdir tmp/cover diff --git a/cmd/envtool/envtool.go b/cmd/envtool/envtool.go index 7151b25ce198..a24ce448a890 100644 --- a/cmd/envtool/envtool.go +++ b/cmd/envtool/envtool.go @@ -33,7 +33,6 @@ import ( "time" "github.com/alecthomas/kong" - "github.com/jackc/pgx/v5" "github.com/prometheus/client_golang/prometheus" "go.uber.org/zap" @@ -99,6 +98,8 @@ func setupAnyPostgres(ctx context.Context, logger *zap.SugaredLogger, uri string return err } + // TODO https://github.com/FerretDB/FerretDB/issues/3452 + var pgPool *pgdb.Pool var retry int64 @@ -119,17 +120,6 @@ func setupAnyPostgres(ctx context.Context, logger *zap.SugaredLogger, uri string defer pgPool.Close() - logger.Info("Creating databases...") - - for _, name := range []string{"admin", "test"} { - err = pgPool.InTransaction(ctx, func(tx pgx.Tx) error { - return pgdb.CreateDatabaseIfNotExists(ctx, tx, name) - }) - if err != nil && !errors.Is(err, pgdb.ErrAlreadyExist) { - return err - } - } - return nil } diff --git a/internal/backends/collection.go b/internal/backends/collection.go index ba41ed6fc1d7..6f0e6e1bad34 100644 --- a/internal/backends/collection.go +++ b/internal/backends/collection.go @@ -73,7 +73,8 @@ func CollectionContract(c Collection) Collection { type QueryParams struct { // TODO https://github.com/FerretDB/FerretDB/issues/3235 Filter *types.Document - OnlyRecordIDs bool // TODO https://github.com/FerretDB/FerretDB/issues/3490 + OnlyRecordIDs bool // TODO https://github.com/FerretDB/FerretDB/issues/3490 + Comment string // TODO https://github.com/FerretDB/FerretDB/issues/3573 } // QueryResult represents the results of Collection.Query method. diff --git a/internal/backends/postgresql/query.go b/internal/backends/postgresql/query.go index d8729972e1db..41674fa1d1c5 100644 --- a/internal/backends/postgresql/query.go +++ b/internal/backends/postgresql/query.go @@ -33,6 +33,7 @@ import ( // prepareSelectClause returns simple SELECT clause for provided db and table name, // that can be used to construct the SQL query. func prepareSelectClause(db, table string) string { + // TODO https://github.com/FerretDB/FerretDB/issues/3573 return fmt.Sprintf( `SELECT %s FROM %s`, metadata.DefaultColumn, @@ -59,6 +60,9 @@ func prepareWhereClause(p *metadata.Placeholder, sqlFilters *types.Document) (st return "", nil, lazyerrors.Error(err) } + // Is the comment below correct? Does it also skip things like $or? + // TODO https://github.com/FerretDB/FerretDB/issues/3573 + // don't pushdown $comment, it's attached to query in handlers if strings.HasPrefix(rootKey, "$") { continue diff --git a/internal/handlers/common/delete_params.go b/internal/handlers/common/delete_params.go index 126fdeda8282..36346f34c155 100644 --- a/internal/handlers/common/delete_params.go +++ b/internal/handlers/common/delete_params.go @@ -28,8 +28,8 @@ type DeleteParams struct { DB string `ferretdb:"$db"` Collection string `ferretdb:"delete,collection"` - Comment string `ferretdb:"comment,opt"` Deletes []Delete `ferretdb:"deletes,opt"` + Comment string `ferretdb:"comment,opt"` Ordered bool `ferretdb:"ordered,opt"` Let *types.Document `ferretdb:"let,unimplemented"` @@ -44,8 +44,6 @@ type DeleteParams struct { type Delete struct { Filter *types.Document `ferretdb:"q"` Limited bool `ferretdb:"limit,zeroOrOneAsBool"` - // TODO https://github.com/FerretDB/FerretDB/issues/2627 - Comment string `ferretdb:"comment,opt"` Collation *types.Document `ferretdb:"collation,unimplemented"` diff --git a/internal/handlers/common/update_params.go b/internal/handlers/common/update_params.go index 614ae57f8c95..d53469734b5a 100644 --- a/internal/handlers/common/update_params.go +++ b/internal/handlers/common/update_params.go @@ -25,9 +25,10 @@ import ( // //nolint:vet // for readability type UpdateParams struct { - DB string `ferretdb:"$db"` - Collection string `ferretdb:"update,collection"` - Updates []Update `ferretdb:"updates"` + DB string `ferretdb:"$db"` + Collection string `ferretdb:"update,collection"` + + Updates []Update `ferretdb:"updates"` Comment string `ferretdb:"comment,opt"` @@ -43,8 +44,6 @@ type UpdateParams struct { // //nolint:vet // for readability type Update struct { - // TODO https://github.com/FerretDB/FerretDB/issues/2627 - // get comment from query, e.g. db.collection.UpdateOne({"_id":"string", "$comment: "test"},{$set:{"v":"foo""}}) Filter *types.Document `ferretdb:"q,opt"` Update *types.Document `ferretdb:"u,opt"` // TODO https://github.com/FerretDB/FerretDB/issues/2742 Multi bool `ferretdb:"multi,opt"` diff --git a/internal/handlers/pg/msg_delete.go b/internal/handlers/pg/msg_delete.go index 4d3d7babf157..0ba0ae8aa90b 100644 --- a/internal/handlers/pg/msg_delete.go +++ b/internal/handlers/pg/msg_delete.go @@ -60,7 +60,6 @@ func (h *Handler) MsgDelete(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, // process every delete filter for i, deleteParams := range params.Deletes { qp.Filter = deleteParams.Filter - qp.Comment = deleteParams.Comment del, err := execDelete(ctx, &execDeleteParams{ dbPool, diff --git a/internal/handlers/sqlite/msg_find.go b/internal/handlers/sqlite/msg_find.go index 0a225c347797..c7cd292c7b90 100644 --- a/internal/handlers/sqlite/msg_find.go +++ b/internal/handlers/sqlite/msg_find.go @@ -66,7 +66,16 @@ func (h *Handler) MsgFind(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, er return nil, lazyerrors.Error(err) } - var qp backends.QueryParams + qp := &backends.QueryParams{ + Comment: params.Comment, + } + + if params.Filter != nil { + if qp.Comment, err = common.GetOptionalParam(params.Filter, "$comment", qp.Comment); err != nil { + return nil, err + } + } + if !h.DisableFilterPushdown { qp.Filter = params.Filter } @@ -81,7 +90,7 @@ func (h *Handler) MsgFind(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg, er // closer accumulates all things that should be closed / canceled. closer := iterator.NewMultiCloser(iterator.CloserFunc(cancel)) - queryRes, err := c.Query(ctx, &qp) + queryRes, err := c.Query(ctx, qp) if err != nil { closer.Close() return nil, lazyerrors.Error(err)