Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
chore: increase batch size of db migration [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Feb 22, 2022
1 parent f66f9a3 commit fbbca4d
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func AddSceneWidgetId(ctx context.Context, c DBClient) error {
col := c.WithCollection("scene")

return col.Find(ctx, bson.D{}, &mongodoc.BatchConsumer{
Size: 50,
Size: 1000,
Callback: func(rows []bson.Raw) error {

ids := make([]string, 0, len(rows))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func AddSceneDefaultTile(ctx context.Context, c DBClient) error {
log.Infof("migration: AddSceneDefaultTile: filter: %+v\n", filter)

return col.Find(ctx, filter, &mongodoc.PropertyBatchConsumer{
Size: 50,
Size: 1000,
Callback: func(properties []*property.Property) error {
log.Infof("migration: AddSceneDefaultTile: hit properties: %d\n", len(properties))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func RemovePreviewToken(ctx context.Context, c DBClient) error {
col := c.WithCollection("project")

return col.Find(ctx, bson.D{}, &mongodoc.BatchConsumer{
Size: 50,
Size: 1000,
Callback: func(rows []bson.Raw) error {

ids := make([]string, 0, len(rows))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func AddSceneAlignSystem(ctx context.Context, c DBClient) error {
col := c.WithCollection("scene")

return col.Find(ctx, bson.D{}, &mongodoc.BatchConsumer{
Size: 50,
Size: 1000,
Callback: func(rows []bson.Raw) error {
ids := make([]string, 0, len(rows))
newRows := make([]interface{}, 0, len(rows))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func SplitSchemaOfProperties(ctx context.Context, c DBClient) error {
return col.Find(ctx, bson.M{
"schema": bson.M{"$exists": true},
}, &mongodoc.BatchConsumer{
Size: 50,
Size: 1000,
Callback: func(rows []bson.Raw) error {
ids := make([]string, 0, len(rows))
newRows := make([]interface{}, 0, len(rows))
Expand Down
3 changes: 3 additions & 0 deletions internal/infrastructure/mongo/migration/migrations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tools/cmd/migrategen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ import "context"
func {{.Name}}(ctx context.Context, c DBClient) error {
// TODO: Write your migration code here
// WARNING:
// If the migration takes too long, the deployment may fail in a serverless environment.
// Set the batch size to as large a value as possible without using up the RAM of the deployment destination.
return nil
}
`))
Expand All @@ -109,6 +113,9 @@ var templ2 = template.Must(template.New("generated2").Parse(`// Code generated b
package migration
// WARNING:
// If the migration takes too long, the deployment may fail in a serverless environment.
// Set the batch size to as large a value as possible without using up the RAM of the deployment destination.
var migrations = map[int64]MigrationFunc{
{{range .}} {{.Key}}: {{.Name}},
{{end}}}
Expand Down

0 comments on commit fbbca4d

Please sign in to comment.