quick question about rake migrate

Migrate applies changes, moving the database from one state to the next, until it is at the latest.

Migrations capture a set of changes in numbered files. When you do ‘rake migrate’ those changes are applied to your database in sequential order and the final number is recorded in a table called ‘schema_version’. If you run ‘rake migrate’ again, the schema version is compared to the highest numbered migration. If the numbers match then the database is considered to be at the latest schema version and no migrations are performed.

If you have previously run a migration and you want to add columns you have 2 choices: 1) you can reverse the previous migration or 2) you can create a new migration.

I tend to do #1 if I am working on some changes and I simply forgot something and I have not yet released the new version. #2 is the primary mode of operation for migrations.

Reversing a migration assumes you have implemented the ‘down’ method. If you have done this then you simple say ‘rake migrate VERSION=[some version number]’. For example, let’s say your latest migration is 005_add_project_table and that you have already done a ‘rake migrate’. To revert to 4 you would do this:

rake migrate VERSION=4

Good luck.