This project is archived and is in readonly mode.
[feature-request] db seed files for each environment.
-
Postmodern
Initial patch here: http://github.com/postmodern/rails/commit/7dd0718239c6747e1a6981aed...
-
Ryan Bigg
- 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
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.rbandconfig/environments. -
Postmodern
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
- 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
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 runI dont use seed files at all in the testing environment.
-
David Trasbo
- State changed from needs-more-info to wontfix
My personal opinion: -1
Why not just use if statements instead?
if Rails.env.development? # ... end if Rails.env.production? # ... end # So on, so forthIf 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' end # So on.Will mark this as won't fix for now. It's not really my decision, but I'll reopen if necessary.
-
Postmodern
Hmm, or we could use:
require File.join('db','seeds',Rails.env)