Does using migrations with Rails/Mongoid/MongoDB make sense?

mongodb, mongoid, ruby-on-rails

Solution

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:

- removing unused fields

- adding new required fields

- setting default values

- renaming fields

- loading required data/fixtures

- ensuring required indexes

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.

Problem

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?

Original source