Articles Feed

Authors

Categories

Rails Migrations and Subversion

by: paul | September 28th, 2006 |

In rails, migrations are generated like so

paul-pagels-computer:~/RailsProjects/project paulpagel$ ruby script/generate migration CreatePacketTimestamp exists db/migrate create db/migrate/013createpacket_timestamp.rb

This creates a numbered migration with an up and a down schema direction. This has been incredibly helpful when dealing with the schema changes. The problem our team has found is doing migrations with subversion.

You run migrations by

paul-pagels-computer:~/RailsProjects/project paulpagel$ rake migrate

Which looks in the schema_info table to find which version of the schema your database is representing, and updates it to the most recent version (the highest number).

The problem comes into play when you have multiple people making migration scripts on their local machine at the same time. If two different people did a migration at the same time and committed them you would end up with two migrations. Which one gets run?

I am not sure how to solve this one yet. I have been loving rails, but this has already has put a dampener on it.

3 Responses to “Rails Migrations and Subversion”

  1. Craig Demyanovich Says:
    Who ever commits first wins! ;-) Just try renaming the migration file from, say, 005_create_customer.rb to 006_create_customer.rb on your machine, mark the conflict resolved, migrate, test and commit. I can't say I've run into this problem yet, but the answer I'm giving is one I read recently.
  2. Paul W Pagel Says:
    Thanks, we have implemented a lock on migrations(raising your hand and yelling migration) which has worked. The problem only comes into place when you don't notice the duplicate names.
  3. Coty Says:
    Yeah, the migrations/version control interaction has bugged me for some timet, too. Sounds as if the hand raising has got it taken care of for you. Thought I'd point this recent post on [simultaneous migrations](http://blog.caboo.se/articles/2006/12/08/simultaneous-migrations) by courtenay, though, as something to keep in mind. I haven't tried it, yet, but it looks promising.

Leave a Reply

#