Last active
March 3, 2024 12:18
-
-
Save jeromedalbert/afab24e80102b41d75d5f5538f1459c4 to your computer and use it in GitHub Desktop.
Automatically resolve Git merge conflicts in Rails schema.rb by picking the most recent date in the conflict (now works with Rails 5 and recent versions of Git). The following files should be in your home ~ directory. Inspired by https://tbaggery.com/2010/10/24/reduce-your-rails-schema-conflicts.html
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
db/schema.rb merge=railsschema |
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
... | |
[core] | |
... | |
attributesfile = /Users/your_user/.gitattributes | |
... | |
[merge "railsschema"] | |
name = newer Rails schema version | |
driver = "ruby -e '\n\ | |
system %(git), %(merge-file), %(--marker-size=%L), %(%A), %(%O), %(%B)\n\ | |
b = File.read(%(%A))\n\ | |
b.sub!(/^<+ .*\\nActiveRecord::Schema\\.define.version: ([0-9_]+). do\\n=+\\nActiveRecord::Schema\\.define.version: ([0-9_]+). do\\n>+ .*/) do\n\ | |
%(ActiveRecord::Schema.define(version: #{[$1, $2].max}) do)\n\ | |
end\n\ | |
File.open(%(%A), %(w)) {|f| f.write(b)}\n\ | |
exit 1 if b.include?(%(<)*%L)'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment