How to seed data with mongoid in existing rails model?
When we start a brand new rails pro开发者_JAVA技巧ject we use db:seed
to populate db data.
During project lifetime in an ActiveRecord backed project we can use migrations to change schema and data. Mongoid doesn't support migrations.
For new fields it's possible to use default_value
option in a field declaration. But what about old one? How should I handle data changes with mongoid?
Is there a better option than to change seed.rb file and use db:seed
?
Thanks in advance.
I just started using https://rubygems.org/gems/mongoid_rails_migrations for adding migrations to mongoid. Seems to work well. Just add the gem to your Gemfile, bundle install, and use migrations the same as in AR.
精彩评论