Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to export a database table to a YAML file?

I have some data in my development database that I would like to utilize as fixtures in my test environment. What is the best way in Rails 2.x to export a database table to a YAML fixture?

like image 304
Mattew Avatar asked Jan 29 '09 04:01

Mattew


People also ask

Can Yaml be used as a database?

Yaml is rather used for config purposes. It is not used for database such as MongoDB because serialization takes longer than json .

Is Yaml machine readable?

YAML is a popular programming language because it is human-readable and easy to understand. It can also be used in conjunction with other programming languages. Becuase of its flexibility and accessibility, YAML is used by the Ansible automation tool to create automation processes, in the form of Ansible Playbooks.


2 Answers

There is a rake task for this. You can specify RAILS_ENV if needed; the default is the development environment:

rake db:fixtures:dump     # Create YAML test fixtures from data in an existing database. 
like image 175
Andrew Vit Avatar answered Sep 21 '22 11:09

Andrew Vit


I have been using YamlDb to save the state of my database.

Install it with the following command:

script/plugin install git://github.com/adamwiggins/yaml_db.git  

Use the rake task to dump the contents of Rails database to db/data.yml

rake db:data:dump 

Use the rake task to load the contents of db/data.yml into the database

rake db:data:load 

This is the creators homepage:

http://blog.heroku.com/archives/2007/11/23/yamldb_for_databaseindependent_data_dumps/

like image 42
Geekygecko Avatar answered Sep 21 '22 11:09

Geekygecko