Thursday, December 21, 2006

Rake: db:migration:conflict

This task originally written by Stephen Chu.

If you are using migrations on a large team, migration conflicts can and do occur. To help avoid conflicts you can add the following task to your codebase and run it after updating and before checking in (hopefully in your commit task).
namespace :db do
namespace :migration do
desc "After downloading migrations from server, check to see if we have conflicting migration numbers."
task :conflict do
existing_migration_numbers = []
Dir.entries("#{RAILS_ROOT}/db/migrate").each do |entry|
migration_number = entry.scan(/^\d+/).first
next if migration_number.nil?
if existing_migration_numbers.include? migration_number
raise ArgumentError, "Migration #{migration_number} is already checked in on the server. Verify your migration numbers."
existing_migration_numbers << migration_number
Post a Comment