Skip to content

Instantly share code, notes, and snippets.

@strax
Created March 24, 2015 16:08
Show Gist options
  • Save strax/c0dcbfa2f9bb54f95787 to your computer and use it in GitHub Desktop.
Save strax/c0dcbfa2f9bb54f95787 to your computer and use it in GitHub Desktop.
Auto-resolving schema.rb version conflicts on Rails 4.0+
db/schema.rb merge=railsschema
[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: (\\d+). do\\n=+\\nActiveRecord::Schema\\.define.version: (\\d+). 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)'"
@rahim
Copy link

rahim commented Mar 19, 2018

❤️ stolen, thank you for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment