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

🙈 keep old import versions #44

Closed
Closed
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ifneq ($(LOCAL_DB_MONGO),mongodb-pilot)
docker run -d -p 27017:27017 --name mongodb-pilot \
-e MONGO_INITDB_ROOT_USERNAME=mongoadmin \
-e MONGO_INITDB_ROOT_PASSWORD=secret \
mongo:4.2.11
mongo:5.0.9
endif

stop-local-db:
Expand Down
37 changes: 21 additions & 16 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ import "time"

// Plugin The plugin information.
type Plugin struct {
ID string `json:"id,omitempty" bson:"id"`
Name string `json:"name,omitempty" bson:"name"`
DisplayName string `json:"displayName,omitempty" bson:"displayName"`
Author string `json:"author,omitempty" bson:"author"`
Type string `json:"type,omitempty" bson:"type"`
Import string `json:"import,omitempty" bson:"import"`
Compatibility string `json:"compatibility,omitempty" bson:"compatibility"`
Summary string `json:"summary,omitempty" bson:"summary"`
IconURL string `json:"iconUrl,omitempty" bson:"iconUrl"`
BannerURL string `json:"bannerUrl,omitempty" bson:"bannerUrl"`
Readme string `json:"readme,omitempty" bson:"readme"`
LatestVersion string `json:"latestVersion,omitempty" bson:"latestVersion"`
Versions []string `json:"versions,omitempty" bson:"versions"`
Stars int `json:"stars,omitempty" bson:"stars"`
Snippet map[string]interface{} `json:"snippet,omitempty" bson:"snippet"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
ID string `bson:"id"`
Name string `bson:"name"`
DisplayName string `bson:"displayName"`
Author string `bson:"author"`
Type string `bson:"type"`
Compatibility string `bson:"compatibility"`
Summary string `bson:"summary"`
IconURL string `bson:"iconUrl"`
BannerURL string `bson:"bannerUrl"`
Readme string `bson:"readme"`
LatestVersion string `bson:"latestVersion"`
Versions []PluginVersion `bson:"versions"`
Stars int `bson:"stars"`
Snippet map[string]interface{} `bson:"snippet"`
CreatedAt time.Time `bson:"createdAt"`
}

// PluginVersion is a plugin version with the correct import.
type PluginVersion struct {
Name string `json:"name" bson:"name"`
Import string `json:"import" bson:"import"`
}

// PluginHash The plugin hash tuple..
Expand Down
39 changes: 34 additions & 5 deletions pkg/db/mongodb/plugindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (m *MongoDB) GetByName(ctx context.Context, name string) (db.Plugin, error)
defer span.End()

criteria := bson.D{
{Key: "name", Value: name},
{Key: "name", Value: primitive.Regex{Pattern: regexp.QuoteMeta(name), Options: "i"}},
}

opts := &options.FindOneOptions{}
Expand All @@ -200,8 +200,8 @@ func (m *MongoDB) GetByName(ctx context.Context, name string) (db.Plugin, error)
return plugin, nil
}

// SearchByName searches for plugins matching with the given name.
func (m *MongoDB) SearchByName(ctx context.Context, name string, page db.Pagination) ([]db.Plugin, string, error) {
// SearchByDisplayName searches for plugins matching with the given display name.
func (m *MongoDB) SearchByDisplayName(ctx context.Context, name string, page db.Pagination) ([]db.Plugin, string, error) {
ctx, span := m.tracer.Start(ctx, "db_search_by_name")
defer span.End()

Expand Down Expand Up @@ -286,8 +286,37 @@ func (m *MongoDB) Update(ctx context.Context, id string, plugin db.Plugin) (db.P
{Key: "id", Value: id},
}

update := bson.D{
{Key: "$set", Value: plugin},
update := bson.A{
bson.D{{Key: "$set", Value: bson.D{{Key: "name", Value: plugin.Name}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "displayName", Value: plugin.DisplayName}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "author", Value: plugin.Author}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "type", Value: plugin.Type}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "compatibility", Value: plugin.Compatibility}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "summary", Value: plugin.Summary}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "iconUrl", Value: plugin.IconURL}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "bannerUrl", Value: plugin.BannerURL}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "readme", Value: plugin.Readme}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "latestVersion", Value: plugin.LatestVersion}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "stars", Value: plugin.Stars}}}},
bson.D{{Key: "$set", Value: bson.D{{Key: "snippet", Value: plugin.Snippet}}}},
// needs mongo > 4.2
bson.D{{Key: "$set", Value: bson.D{{Key: "versions", Value: bson.D{
{Key: "$concatArrays", Value: bson.A{"$versions", bson.D{
{Key: "$filter", Value: bson.D{
{Key: "input", Value: plugin.Versions},
{Key: "cond", Value: bson.D{
{Key: "$not", Value: bson.D{
{Key: "$in", Value: bson.A{
"$$this.name", "$versions.name",
}},
}},
}},
},
}},
}},
}},
}},
},
}

opts := &options.FindOneAndUpdateOptions{}
Expand Down
Loading