Skip to content

Instantly share code, notes, and snippets.

@ragesoss
Created March 31, 2017 19:41
Show Gist options
  • Save ragesoss/793b4c1b1205da9a101e2dc076126fe6 to your computer and use it in GitHub Desktop.
Save ragesoss/793b4c1b1205da9a101e2dc076126fe6 to your computer and use it in GitHub Desktop.
Add version numbers to pre-5.0 Ruby on Rails ActiveRecord migrations.
# Run from db/migrate to fix your old un-versioned migrations, so that they don't break on Rails 5.1
Dir.glob('*').each do |migration|
versioned_migration = File.read(migration).gsub("< ActiveRecord::Migration\n", "< ActiveRecord::Migration[4.2]\n")
File.open(migration, 'w') do |output|
output << versioned_migration
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment