Created
April 22, 2009 01:21
-
-
Save kmayer/99521 to your computer and use it in GitHub Desktop.
An example of how to handle migrations that *might* fail because they've already happened.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example of how to handle migrations that *might* fail because they've already happened. | |
class FixUpMigrations < ActiveRecord::Migration | |
def self.up | |
say_with_time %{ | |
If you are transitioning from 0.6.9 to 0.7.1, these migrations | |
were lost. We're not worried if the columns already exist. | |
} do | |
maybe_add_column 'duplicate column name', | |
:pages, :is_preview, :boolean, :default => false | |
maybe_add_column 'duplicate column name', | |
:snippets, :is_preview, :boolean, :default => false | |
maybe_add_column 'duplicate column name', | |
:layouts, :is_preview, :boolean, :default => false | |
remove_column :page_part_revisions, :page_part_id | |
end | |
end | |
def self.down | |
end | |
private | |
def self.method_missing(m, *args) | |
if m.to_s =~ /^maybe_(.*)/ | |
begin | |
whoops = args.shift | |
self.send($1, *args) | |
rescue ActiveRecord::StatementInvalid => e | |
if e.to_s.include? whoops | |
say ' skipping' | |
true | |
else | |
raise e | |
end | |
end | |
else | |
super | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment