This project is archived and is in readonly mode.

#4908 ✓wontfix

[feature-request] db seed files for each environment.

Reported by Postmodern | June 20th, 2010 @ 12:33 AM

I keep running into scenarios where I need to seed the database of the current environment differently. It would be very useful, and somewhat trivial to support seed files for each environment. One could still have the usual db/seeds.rb file for all environments. Additionally, one could also have db/seeds/production.rb, db/seeds/development.rb and db/seeds/test.rb.

Comments and changes to this ticket

  • Postmodern
  • Ryan Bigg

    Ryan Bigg June 21st, 2010 @ 04:04 AM

    • State changed from “new” to “needs-more-info”

    You'll need to add tests if you want this in. I'm on the fence about this. The data I load to test things in development is exactly the same data I use in production. What use case is there for having two separate seed files?

  • Postmodern

    Postmodern June 21st, 2010 @ 04:15 AM

    Alright, I will get on writing tests.

    One common scenario for having multiple seeds files, is using a very large and arbitrary data-set for development, in order to test the performance of complex queries.

    The other scenario I recently ran into was designing an app that used a shared production database, where certain tables were populated by other backend python scripts; maintained by another developer. In my testing and development databases, which I controlled, I still needed to load in a canned snapshot of the data from the production database.

    Finally, this would mirror the same file organization used by config/environment.rb and config/environments.

  • Postmodern

    Postmodern June 21st, 2010 @ 04:21 AM

    Where would I write tests against active_record/railties/database.rake? Most of the tests in activerecord appear to be testing the ORM code.

  • Robert Pankowecki

    Robert Pankowecki August 9th, 2010 @ 03:42 PM

    • Importance changed from “” to “Low”

    What use case is there for having two separate seed files?

    Keeping seed.rb with data that must be in application to run properly ex. some dictionaries. Keeping data that makes writing tests easier in seeds/test.rb (works like fixtures for me). Keeping data that makes using the application easier in seeds/development.rb ex. few more users, some objects already created, permissions already set and so on...

    I hope that this feature will be implemented :-)

  • CodeOfficer

    CodeOfficer September 30th, 2010 @ 04:26 AM

    I'd also love to see an environment based solution as there are 2 ways that I tend to use seeds:

    1) seeding my development environment with lots of dummy data to flush out views
    2) seeding production on deploy with data the app needs to run

    I dont use seed files at all in the testing environment.

  • David Trasbo

    David Trasbo October 10th, 2010 @ 06:25 PM

    • State changed from “needs-more-info” to “wontfix”

    My personal opinion: -1

    Why not just use if statements instead?

    if Rails.env.development?
     # ...
    if Rails.env.production?
      # ...
    # So on, so forth

    If scalability is the issue, you could move environment specific seeds into a separate file and require it:

    if Rails.env.development?
      require 'db/seeds/development'
    # So on.

    Will mark this as won't fix for now. It's not really my decision, but I'll reopen if necessary.

  • Postmodern

    Postmodern October 11th, 2010 @ 12:14 AM

    Hmm, or we could use:

    require File.join('db','seeds',Rails.env)
  • james2m

    james2m April 4th, 2011 @ 04:58 PM

    @postmodern If it's useful to you, I put together a little gem to do this Seedbank. It lets you have seeds for different environments.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>