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
2009-01-29 04:59:12
The currently maintained repository is now at http://github.com/ludicast/yaml_db
Sney
2010-04-18 17:01:52
+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
2009-02-05 02:39:54
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
2010-04-16 05:43:31
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
2010-04-16 05:45:07