Pensieri di un lunatico minore

20 February 2006 Ruby

Rails schema migrations

Rails has developed a bit more maturity now, and has the concept of “schema migrations” in the ActiveRecord component. I decided that rather than even try and “jump-start” my system with a normal initial schema, that I’d try and use the migration facilities. Some observations follow.

First, ActiveRecord::Migration does not implicitly wrap it’s DDL in a transaction as far as I can determine. This means that if anything goes wrong, you could leave your schema in an unusable state. For PostgreSQL at least, DDL can exist in a transaction, so I decided to wrap it up in: BEGIN and END so that if something goes wrong, things get rolled back. Not doing this by default is a bad idea1.

Next, data types supported by ActiveRecord are woefully simplistic, at least for automatic schema creation. Your choices are: