-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: change dot in namespace name and hostname to -
- Loading branch information
1 parent
43130a7
commit 7ef0ca7
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |