Skip to content

Conversation

@V-R-Dighe
Copy link

Resolves #779

@coveralls
Copy link

coveralls commented Aug 25, 2022

Coverage Status

Coverage increased (+0.02%) to 57.793% when pulling 2262309 on V-R-Dighe:mongodb_setversion_enhancement into 4bd8366 on golang-migrate:master.

Copy link
Member

@dhui dhui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and thanks for fixing the linter errors!

}
_, err := migrationsCollection.InsertOne(context.TODO(), bson.M{"version": version, "dirty": dirty})
opts := options.Update().SetUpsert(true)
_, err := migrationsCollection.UpdateOne(context.TODO(), bson.M{}, bson.D{{Key: "$set", Value: bson.M{"version": version, "dirty": dirty}}}, opts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work with existing DBs? e.g. how does this update existing entries?
Right now, there's only ever one document in the migrations collection.

Copy link
Author

@V-R-Dighe V-R-Dighe Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @dhui, it is working with existing entries in DB. I tested it by adding some sleep between the SetVersion functions in migrate.js and monitored changes in the document. It updated the dirty flag for the existing entry and for the new version entry it replaced the document with a new document. At the end of the migration, the collection contained only a single document.

@V-R-Dighe
Copy link
Author

Hello Team,
cc: @dhui

Please review and let me know if anything more is needed from my end.

Thanks,
Vaibhav Dighe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better implementation for mongodb.SetVersion

3 participants