Skip to content

Instantly share code, notes, and snippets.

@eliotsykes
Last active October 21, 2019 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliotsykes/6878a877ec1efd2f36004dd098896623 to your computer and use it in GitHub Desktop.
Save eliotsykes/6878a877ec1efd2f36004dd098896623 to your computer and use it in GitHub Desktop.
Versioned migrations support in Rails 4.2
# This file lives at config/initializers/versioned_migrations.rb
def supports_versioned_migrations?
Rails::VERSION::MAJOR >= 5
end
if supports_versioned_migrations?
ActiveSupport::Deprecation.warn(
"Versioned migrations are supported in your Rails version, you can delete file: #{__FILE__}"
)
return
end
# Rails < 5 does not support versioned migrations and does not have the
# ActiveRecord::Migration.[version] method.
#
# Add the ActiveRecord::Migration.[version] method.
module VersionedMigrations
def [](version)
# Return the regular ActiveRecord::Migration class used before Rails 5
ActiveRecord::Migration
end
end
ActiveRecord::Migration.extend(VersionedMigrations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment