Rails 4: Export database to YAML

后端 未结 1 548
感动是毒
感动是毒 2021-02-04 12:44

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?).

Howeve

相关标签:
1条回答
  • 2021-02-04 13:36

    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

    0 讨论(0)
提交回复
热议问题