A Standard for Bootstrapping Rails

rails

Mon Aug 04 12:37:00 -0700 2008

Rails provides a standardized way - convention over configuration - to do all the common tasks a CRUD web app would want to do. One rather glaring omission, however, is that there’s no standard for what to do to set up a new app.

A rake task is the obvious choice, but there’s no convention on what the task should be named. For example: Mephisto uses `rake db:bootstrap`, while Insoshi uses `rake install`.

Some apps don’t need anything other than the database schema, so rake db:schema:load followed by rake db:migrate will do the trick. Even this is hardly ideal: it’s still two steps instead of one; and some apps need one, some the other, and some both, in that order. Beast, for example, uses db:schema:load to load the schema, and a lone migration to fill in data.

Luke Francl took a look at this issue a while back. He calls it “seed data,” because in almost every case the setup process is filling initial data into the database. (His conclusion, unfortunately, is that there’s no good way to do it.)

If the install process is all about seed data, is this a job for `yaml_db`? After all, rake db:data:load is the twin of rake db:schema:load, which is already a necessary part of the setup process. So running rake db:load, which runs both tasks in the proper sequence, would be the closest thing to a single-step install based on existing rake tasks. Except that yaml_db is not a standard part of Rails, so we’re back to square one.

My proposal for a solution is as follows: pick one standard task name for setup of an app. By default it runs db:schema:load followed by db:migrate. Then individual apps can tack on their extensions to load seed data or do whatever they want. Some may choose to load fixtures, others might embed ActiveRecord creates straight into the task. Personally I’ll probably use yaml_db. But as long as there’s a standard hook for launching the setup process, this should satisfy everyone.

The only remaining question is the task name. Insoshi’s rake install seems as good as anything to me; what do you guys think? Heroku is going to standardize on one name soon, and whatever we pick will probably be a subtle force toward making that the community-wide standard. So chime in now if you have an opinion on the matter.