Project

General

Profile

You should commit db/schema.rb in the repo!

Added by Giorgio Gonnella almost 15 years ago

Hi guys,

you've got a nice project. Compliments.

You are doing only a big mistake that you can correct quickly: you should really commit the file db/schema.rb in your repository. This is standard for rails application.

Let me explain you (reference: the first lines in db/schema.rb and the API documentation): doing rake db:migrate is not the best approach; on one side you force people to run 101 steps, when they only need 1 step actually, on the other side you may in future change your models for example and break some of the oldest migrations: migrations are for devs not for end users.

The right approach is to let people run db:schema:load to install the database. For this to work you have to commit the db/schema.rb in the repository. The the database is generated in one step that is guaranteed to work always. And is standard rails.

Bye and good luck.
Giorgio


Replies (4)

RE: You should commit db/schema.rb in the repo! - Added by Jean-Philippe Lang almost 15 years ago

Giorgio Gonnella wrote:

migrations are for devs not for end users.

And how end users migrate their database when they upgrade ?

RE: You should commit db/schema.rb in the repo! - Added by Giorgio Gonnella almost 15 years ago

Of course you need also migrations. (Me stupid!!! :) )

However that doesn't change the fact that rails core people reccomend to commit also db/schema.rb and new users should create their databases with rake db:load and not rake db:migrate:

from schema.rb:

  1. [...] If you need
  2. to create the application database on another system, you should be using db:schema:load, not running
  3. all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
  4. you'll amass, the slower it'll run and the greater likelihood for issues). #
  5. It's strongly recommended to check this file into your version control system.

RE: You should commit db/schema.rb in the repo! - Added by Jean-Philippe Lang almost 15 years ago

Giorgio Gonnella wrote:

the more migrations you'll amass, the slower it'll run

It only takes a few seconds to migrate a database

and the greater likelihood for issues

As I said, migrations are required for upgrades. So migrations have to run fine.

Another point is that I use migrations to create a few objects (like the default admin account).
You won't find them in schema.rb.

RE: You should commit db/schema.rb in the repo! - Added by Giorgio Gonnella almost 15 years ago

OK, as long as the code for your models does not change too much, migrations will probably run fine.
If your migrations load data, they are more likely to break as your models change. However this is more
an issue for larger projects.

In the current edge there is a feature to load data (see http://ryandaigle.com/articles/2009/5/13/what-s-new-in-edge-rails-database-seeding ), for older versions you could just implement it as a rake task.

I didn't want to start a flame anyway, so if you like that more, go on with migrations, just be sure to test the process often.

    (1-4/4)