Last active
October 21, 2019 13:04
-
-
Save eliotsykes/6878a877ec1efd2f36004dd098896623 to your computer and use it in GitHub Desktop.
Versioned migrations support in Rails 4.2
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
# 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