Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created November 9, 2011 23:02
Show Gist options
  • Save pmarreck/1353461 to your computer and use it in GitHub Desktop.
Save pmarreck/1353461 to your computer and use it in GitHub Desktop.
A little lib to cause migrations to skip duplicates instead of failing.
class MyCompany::Migration < ActiveRecord::Migration
def self.add_column(*args)
begin
super
rescue => e
if e.message =~ /Duplicate/
puts "WARNING, a migration line was skipped due to it already existing: #{e.message}"
else
raise e
end
end
end
def self.rename_column(*args)
begin
super
rescue => e
if e.message =~ /Duplicate/
puts "WARNING, a migration line was skipped due to it already existing: #{e.message}"
else
raise e
end
end
end
def self.add_index(*args)
begin
super
rescue => e
if e.message =~ /Duplicate/
puts "WARNING, a migration line was skipped due to it already existing: #{e.message}"
else
raise e
end
end
end
def self.create_table(*args, &block)
begin
super
rescue => e
if e.message =~ /Duplicate/
puts "WARNING, a migration line was skipped due to it already existing: #{e.message}"
else
raise e
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment