Skip to content

Commit

Permalink
Merge pull request #3789 from jamsman94/feature/labelRestriction
Browse files Browse the repository at this point in the history
add index to label collection
  • Loading branch information
jamsman94 authored Nov 1, 2024
2 parents cdfa112 + 52192ad commit 0ed4750
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/microservice/aslan/core/common/repository/mongodb/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

type LabelColl struct {
Expand All @@ -47,8 +48,15 @@ func (c *LabelColl) GetCollectionName() string {
}

func (c *LabelColl) EnsureIndex(ctx context.Context) error {
// currently no query is required for the label defining collection
return nil
mod := mongo.IndexModel{
Keys: bson.D{
bson.E{Key: "key", Value: 1},
},
Options: options.Index().SetUnique(true),
}

_, err := c.Indexes().CreateOne(ctx, mod)
return err
}

func (c *LabelColl) Create(args *models.Label) error {
Expand Down

0 comments on commit 0ed4750

Please sign in to comment.