Migration Naming Collisions

written by stonean on June 17th, 2008 @ 12:14 PM

In a very short amount of time, I realized that using a timestamp for the migration number was too cumbersome and I think it is a mistake that will hopefully be corrected in future versions of Rails.

That started me thinking about the conversion that would be necessary to move away from timestamped migrations and I didn't like what I was foreseeing. Instead of going through that headache, I decided to stick with the standard version number scheme, this post shows you how to do this.

So how do you solve the migration collision issue without this timestamp feature? This is actually easy, just create a file named "version" in your db/migration directory. If you are working on a team and are going to create a new migration (or more), just edit this file and put the highest number migration in your source and commit it.

This will prevent you from having to commit your migration and your team can be notified of the next version number they should use.

After all, as developers, we need to communicate when working on a project. If you don't, you are asking for trouble.

Comments

  • D. Rothlisberger on 01 Jul 22:35

    AND... modify the code from "the post you linked":http://blog.stonean.com/2008/06/timestamped-migrations.html so that it looks in this "version" file when generating new migration numbers, and automatically updates said file with the new version number.
  • stonean on 02 Jul 11:52

    D., That is a good idea and should probably be added via a plugin. Thanks for the comment, -andy

Comments are closed