Tuesday, July 25, 2006

Migrations in Rails so rock.

Just create your models with


script/generate model TestModel


then run


rake migrate


If you discover you need to change something in the table, edit the migration file, 001_create_test_model.rb, then migrate to version 0 to drop all the tables:


rake migrate VERSION=0


then migrate again normally to update your database:


rake migrate


I had a really sweet solution with a custom built Makefile, it was truly sweet, and used dependencies and everything, but really, this way is so much better, and would work with any kind of database that Rails supports, so it's "The Right Thing". Drat, I'm not looking forward to recoding all my tables as migrations, but I am going to do it, and not slack off with "rake db_schema_dump" which just looks like it sucks, unless you have a truly massive database already built. Well, I do, it's lots and lots of tables, but still, I will be strong. :)