Should I create AR migrations as I'm changing my models? I am using Mongoid and MongoDB so I do not see any benefits. The only benefit that I can think of is renaming a field - but that I can also do with small script. Would that even work? My gut is telling me that I do not need migrations, but I'd like to hear from someone with more experience.
What is the best practice? Should I use migrations with MongoDB?
This is why you need a migration tool for MongoDB And as software evolves, we may need to fix mistakes on the data schema or adapt existing data as requirements change.
Mongoid 7.0. 5 or higher is required to use Rails 6.0. This generator will create the config/mongoid. yml configuration file, which is used to configure the connection to the MongoDB deployment.
The answer is yes: it makes a lot of sense. Nevertheless, Rails wasn't originally built to use a document database so you must use a separate gem in place of Active Record. MongoMapper and Mongoid are the two leading gems that make it possible use MongoDB as a datastore with Rails.
A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.
Since MongoDB does not (as at 2.6) provide any server-side schema enforcement, data migration scripts are not strictly required. This can be particularly helpful for speed of development.
However, it may still make sense for you to create migrations for your production data if you want to practice good "data hygiene" and ensure consistency across different deployments.
For example:
You certainly have the choice of doing any of the above as one-off scripts or handling exception cases in your application code. For example, you can lazily add missing fields or defaults as documents are loaded from the database for editing.
For Mongoid in particular you may want to try the mongoid_rails_migrations gem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With