Created
October 18, 2013 09:41
-
-
Save zaki/7039134 to your computer and use it in GitHub Desktop.
Cross-migration dependency
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
class Migration1 < ActiveRecord::Migration | |
def change | |
add_column :models, :test_1, :integer | |
Model.update_first | |
end | |
end |
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
class Migration1 < ActiveRecord::Migration | |
def change | |
add_column :models, :test_2, :integer | |
end | |
end |
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
# 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