Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not create databases during local setup #3572

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ tasks:
{{.SERVICES}}

env-setup:
deps: [gen-version]
deps: [gen-version, build-envtool]
cmds:
- bin/envtool{{exeExt}} setup

Expand Down Expand Up @@ -143,6 +143,7 @@ tasks:
- go generate -x ./build/version

build-envtool:
run: once
cmds:
- go build -v -o bin/ ./cmd/envtool/

Expand All @@ -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

Expand Down
14 changes: 2 additions & 12 deletions cmd/envtool/envtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion internal/backends/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions internal/backends/postgresql/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// 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,
Expand All @@ -46,7 +47,7 @@
var args []any

iter := sqlFilters.Iterator()
defer iter.Close()

Check failure on line 50 in internal/backends/postgresql/query.go

View workflow job for this annotation

GitHub Actions / golangci-lint

iter.Close undefined (type iterator.Interface[string, any] has no field or method Close)

// iterate through root document
for {
Expand All @@ -59,6 +60,9 @@
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
Expand Down
4 changes: 1 addition & 3 deletions internal/handlers/common/delete_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`

Expand Down
9 changes: 4 additions & 5 deletions internal/handlers/common/update_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand All @@ -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"`
Expand Down
1 change: 0 additions & 1 deletion internal/handlers/pg/msg_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions internal/handlers/sqlite/msg_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@
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
}

Check warning on line 76 in internal/handlers/sqlite/msg_find.go

View check run for this annotation

Codecov / codecov/patch

internal/handlers/sqlite/msg_find.go#L75-L76

Added lines #L75 - L76 were not covered by tests
}

if !h.DisableFilterPushdown {
qp.Filter = params.Filter
}
Expand All @@ -81,7 +90,7 @@
// 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)
Expand Down
Loading