--
You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.
To post to this group, send email to rails-...@googlegroups.com.
To unsubscribe from this group, send email to rails-oceani...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
However, I think it's not uncommon to have migrations (especially for
data) that are dependent on model code, which itself can change. In
that case, migrations still provide a valuable service in being able
to roll back and forward between recent versions of the database. You
probably didn't want to deploy a new instance by running all
migrations anyway.
That's where the schema comes in.
Schema + seeds should == a fresh database, ready to use.
I use migrations for structure and data changes, and keep them
isolated from models wherever that can be done easily. I depend on the
schema + seeds always producing a fresh, working DB.
I think that's usually a good way to go. I'd reconsider the approach
if I had some (rare) application where data is more critical, and a
"fresh" DB isn't useful.
Cheers,
Chris
Using seed files for "initial app load" are not so good, or at least, get used once. Because once you have an app in production, you will never do an initial app load again, you'll be restoring from a backup.
Also, using seeds to improve or change data is not good because they are not versioned. You are better off doing this in a migration, and then adjusting your seed file so it works for the new developer coming on board.
For example, getting a new developer on board can be a pain, so we always do the following on our apps:
The README contains "this is what you need to do to get the app running" for a new developer. This includes where the official git repository is, what database is needed, any external tools (sphinx, redis etc) and installation instructions for those, any other external dependencies (s3, reporting and the like) as well as some general information about the production environment (where it is hosted and what monitoring services are on it, like newrelic.com and stillalive.com).
Note, we don't store production passwords in that README, we put them in our encrypted vault that we use for our client and application secrets as part of our Sentinel service.
Finally, all config/*.yml files are saved as config/*.example.yml with the basics of what you need for development. You copy these over to get into development quickly.
So with all of the above done, the new developer reads that to get into development they need to:
rake db:schema:load
rake db:seed
And they have a usable development environment with all the required logins already setup.
My 2 cents.
Mikel Lindsaar
http://rubyx.com/
http://lindsaar.net/
On 22/09/11 6:05 PM, Tianwen Chen wrote:
> Hi everyone,
>
> I just want to raise a discussion as titled and try to find out some
> best practices.
I feel there are actually three levels of "seed data" in a lot of apps,
each a superset of the previous:
1) Bare minimum required data for tests to run
2) Seed data for production
3) Development data
The task to load production should be idempotent, but you can get away
with the others not being (just blow away the DB, load).
Ideally your production task is smart enough to deal with changing data
and can auto-migrate it for you.
Xav