Module: ActiveRecord::Migration::Compatibility
| Relationships & Source Files | |
| Namespace Children | |
|
Classes:
| |
| Defined in: | activerecord/lib/active_record/migration/compatibility.rb |
Constant Summary
-
V8_2 =
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 32
This file exists to ensure that old migrations run the same way they did before a
::Railsupgrade. e.g. if you write a migration on::Rails6.1, then upgrade to::Rails7, the migration should do the same thing to your database as it did when you were running::Rails6.1“Current” is an alias for
::ActiveRecord::Migration, it represents the current::Railsversion. New migration functionality that will never be backward compatible should be added directly to::ActiveRecord::Migration.There are classes for each prior
::Railsversion. Each class descends from the next::Railsversion, so: 5.2 < 6.0 < 6.1 < 7.0 < 7.1 < 7.2 < 8.0 < 8.1 < 8.2If you are introducing new migration functionality that should only apply from
::Rails7 onward, then you should find the class that immediately precedes it (6.1), and override the relevant migration methods to undo your changes.For example,
::Rails6 added a default value for theprecisionoption on datetime columns. So in this file, theCompatibility::V5_2class sets the value ofprecisiontonilif it’s not explicitly provided. This way, the default value will not apply for migrations written for 5.2, but will for migrations written for 6.0.Current
Class Method Summary
Class Method Details
.find(version)
[ GitHub ]# File 'activerecord/lib/active_record/migration/compatibility.rb', line 6
def self.find(version) version = version.to_s name = "V#{version.tr('.', '_')}" unless const_defined?(name) versions = constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete("V").tr("_", ".").inspect } raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}" end const_get(name) end