Skip to content

Instantly share code, notes, and snippets.

@kmayer
Created April 22, 2009 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmayer/99521 to your computer and use it in GitHub Desktop.
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.
# 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