views:

2648

answers:

4

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?

+8  A: 

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/

Philz
The currently maintained repository is now at http://github.com/ludicast/yaml_db
Sney
+4  A: 

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.
Andrew Vit
db:fixtures:dump on Rails? I don't see it on 2.3.5.
J. Pablo Fernández
looks like it's been extracted from ActiveRecord. You can add it back with this plugin:http://github.com/topfunky/ar_fixturesThen run: rake db:fixtures:dump MODEL=ModelName
Brian Armstrong
+2  A: 

rake db:fixtures:dump

has been changed to

rake db:extract_fixtures

Zoli
+ perfect, Thanks for this.
Jirapong
A: 

This plugin will add the functionality you want. It was extracted from ActiveRecord so no longer comes by default.

script/plugin install http://github.com/topfunky/ar_fixtures

Then run:

rake db:fixtures:dump MODEL=ModelName

Brian Armstrong