views:

477

answers:

4

I've seen some plugins and custom rake tasks to dump the active db to fixtures, but I'm not sure what the prevailing technique is.

Basically, I want the opposite of rake:db:fixtures:load so that I can put basic db information (the admin user account, for one) into svn for when we deploy. I don't want to have to create fixtures manually for things like sample data that would take a long time.

When we deploy I want to be able to just run

rake db:migrate
rake db:fixtures:load

And be off to the races.

What is the best/preferred method for doing this in rails?

EDIT:

So it seems there is no standard way to do an opposite rake task of db:fixtures:load.

I don't want to use migrations, because I want a standard way of doing this for all my projects, and I don't like the idea of putting any more than maybe the admin account in a migration. Second, I've been rethinking the idea of using the fixtures. I've decided on using yaml_db because it uses rake tasks:

rake db:data:dump
rake db:data:load

The data will wind up in a YAML file without distrupting test fixtures (which could be different, now that I think about this more carefully). Also, if a major distribution tool like Heroku is using it, I don't have to worry about support/longevity issues.

I suppose this is closest to "standard" that I will find.

Thanks for all the great responses.

+1  A: 

It doesn't use exactly the same format as db:fixtures:load would expect, but ar_fixtures makes dumping and loading data as YAML files pretty easy.

jdl
+4  A: 

Heroku uses the YamlDB Gem

http://www.github.com/adamwiggins/yaml_db/tree/master

Lichtamberg
+1  A: 

I think if is the the standard admin information you might be better off to put that in the migrations. fixtures should ideally be used only for testing.

so1o
If there is any more data than an admin account, I don't like the idea of using migrations. I want a standard procedure for all my rails projects.
cgyDeveloper
You are right about only using fixtures for testing, though. The more I thought about this, the more I realized the data should be in a separate file from fixtures or migrations.
cgyDeveloper
+1  A: 

there is no Standard way to do it. Only a standard way to load fixtures:

rake db:fixtures:load

But there are plenty of examples on the internet:

Vitaly Kushner