Skip to content

Instantly share code, notes, and snippets.

@zaki
Created October 18, 2013 09:41
Show Gist options
  • Save zaki/7039134 to your computer and use it in GitHub Desktop.
Save zaki/7039134 to your computer and use it in GitHub Desktop.
Cross-migration dependency
class Migration1 < ActiveRecord::Migration
def change
add_column :models, :test_1, :integer
Model.update_first
end
end
class Migration1 < ActiveRecord::Migration
def change
add_column :models, :test_2, :integer
end
end
# at the time of writing migration 1
class Model < ActiveRecord::Base
def self.update_first
Model.first.update_attributes!(test_1: 1)
end
end
# at the time of writing migration 2
class Model < ActiveRecord::Base
def self.do_something
Model.first.update_attributes!(test_1: 1, test_2: 2)
end
end
# when these two separate changes get merged together
# migration 1 will fail because the code already
# references the attribute test_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment