Environment Specific Data

I’m trying to figure out the best way to manage multiple sets of data
across different environments. I have a situation where I want to
automatically load some dummy data into my development environment but
I do not want that data to be loaded when I deploy to production. I
would imagine that this is a relatively common situation and I’m
wondering what people consider to be the best practice for dealing
with this type of issue.

My latest idea is to simply create data only migrations for my dev
data and just wrap the entire body of the up method with with an --if
RAILS_ENV == ‘development’-- This will probably work fine for my
needs, but it seems a little hacky and the Agile Web Dev w/ Rails book
actually specifically warns against using migrations to load data not
intended for production (even though they don’t follow their own
advice in the example app) so I’m thinking there’s got to be a better
way or at least some existing convention for dealing with this
problem.

Any ideas or tips would be much appreciated.

Thanks in advance.

-Mike

you could probably use the same trick in the fixtures.

<% if RAILS_ENV == ‘development’ then %>

<% end %>

I’ve mentioned this on a similar thread… I find Rake tasks to be
especially
valuable for setting up a database.

In lib/tasks, create a file called import.rake. In there, do something
like

namespace :db do

namespace :development do

desc "bootstraps the dev database"
task :import => :environment do

  User.create :login=>"admin", :password=>"1234",

:password_confirmation=>“1234”, :email=>[email protected]
Product.create :name=>“Widget”, :price=>15.99, :url=>
http://www.foo.com/widget.jpg

end

end # end development namespace

end # end db namespace

So then

rake db:development:import

That’s a really simple approach. You could get a little more
sophistcated
with Rake though and determine what to do based on the environment. This
is
verbose to show you some possibilities.

Hope that helps!

On Nov 27, 2007 3:47 AM, Thorsten M.
[email protected]