[go: nahoru, domu]

Skip to content

Commit

Permalink
api: change dot in namespace name and hostname to -
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoveiga authored and gustavosbarreto committed Jun 7, 2021
1 parent 43130a7 commit 7ef0ca7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/store/mongo/migrations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func GenerateMigrations() []migrate.Migration {
migration_20,
migration_21,
migration_22,
migration_23,
}
}

Expand Down
45 changes: 45 additions & 0 deletions api/store/mongo/migrations/migration_23.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package migrations

import (
"context"

"github.com/sirupsen/logrus"
migrate "github.com/xakep666/mongo-migrate"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)

var migration_23 = migrate.Migration{
Version: 23,
Description: "change dot in namespace name and hostname to -",
Up: func(db *mongo.Database) error {
logrus.Info("Applying migration 23 - Up")
if _, err := db.Collection("namespaces").UpdateMany(context.TODO(), bson.D{}, []bson.M{
{
"$set": bson.M{"name": bson.M{
"$replaceAll": bson.M{"input": "$name", "find": ".", "replacement": "-"},
},
},
},
}); err != nil {
return err
}

if _, err := db.Collection("devices").UpdateMany(context.TODO(), bson.D{}, []bson.M{
{
"$set": bson.M{"name": bson.M{
"$replaceAll": bson.M{"input": "$name", "find": ".", "replacement": "-"},
},
},
},
}); err != nil {
return err
}

return nil
},
Down: func(db *mongo.Database) error {
logrus.Info("Applying migration 23 - Down")
return nil
},
}

0 comments on commit 7ef0ca7

Please sign in to comment.