Rails 4: Export database to YAML

别来无恙 提交于 2019-12-20 10:40:04

问题


With Rails 2/3 it was possible and easy to export (dump) a database to YAML using one of a few plugins (see Best way to export a database table to a YAML file?).

However, none of these plugins seem to be compatible with Rails 4. Is there still an easy way to do this?


回答1:


The method indicated in the post linked in the question is still valid, but the code is not anymore a plugin: it's the yaml_db gem.

The repository is at https://github.com/yamldb/yaml_db

To dump the db, add the gem to the Gemfile, issue

bundle update 

and then issue:

rake db:data:dump

the dump file is:

db/data.yml

If, like me, you hit the error

undefined method `[]=' for #<ActiveRecord::Result:0x007ff34c76d508>

it can be fixed by following the instructions given in this ticket:

https://github.com/ludicast/yaml_db/pull/45

All you should have to do is add

gem 'yaml_db', github: 'jetthoughts/yaml_db', ref: 'fb4b6bd7e12de3cffa93e0a298a1e5253d7e92ba'

to the Gemfile



来源:https://stackoverflow.com/questions/18748599/rails-4-export-database-to-yaml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!