Why are schema.rb, migrations, models separated?

Long story short: I've been looking at Grails and noticed their models
contain both the schema information as well as the normal validation,
constraint information.

Does doing it that way pose some serious deficiencies? I find that I
get confused with schemas being in an entirely different location than
the constraints and validation of them.

It is the way it is. :slight_smile:

Well that’s not very helpful at all, is it? In all seriousness, the main thing you should realize is that a model in Rails looks at an existing table and builds methods to access the columns in your table. You don’t need a migration / schema to have a model.

Migrations in Rails are there to build the database for you but once that’s done, nothing in Rails ever looks at them again. They’re more of a utility than anything else.

Other ORM libraries, notably DataMapper, take an approach similar to the one you describe in Grails. ActiveRecord, however, prefers minimal configuration. Also, you might be interested to know that Migrations were not introduced until Rails 1.1.

If you get confused, there’s a wonderful plugin called annotate_models that I use on all my projects. It puts the schema info as comments in your models and fxtures so you have them as a reference as well as in your docs.

I'll definitely be checking out the annotate_models plugin. I
remember briefly looking at DataMapper, but I haven't tried doing
anything in it.

Thank you very much. :slight_smile: