aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2015-12-06 06:07:12 +1030
committerMatthew Draper <matthew@trebex.net>2015-12-15 17:18:08 +1030
commit6940dc860c4b25bff2eded370f2af4316de15a30 (patch)
treef4c2f8ad4ec92a0aeaddb8f3ea6c8d548726bc44 /activerecord/lib/active_record/migration.rb
parentde2135209f39a4d336916feceab972bc89dc93de (diff)
downloadrails-6940dc860c4b25bff2eded370f2af4316de15a30.tar.gz
rails-6940dc860c4b25bff2eded370f2af4316de15a30.tar.bz2
rails-6940dc860c4b25bff2eded370f2af4316de15a30.zip
Add migration versioning via Migration subclasses
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r--activerecord/lib/active_record/migration.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index ca2537cdc3..53a84c1342 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -476,6 +476,32 @@ module ActiveRecord
# are in a Migration with <tt>self.disable_ddl_transaction!</tt>.
class Migration
autoload :CommandRecorder, 'active_record/migration/command_recorder'
+ autoload :Compatibility, 'active_record/migration/compatibility'
+
+ # This must be defined before the inherited hook, below
+ class Current < Migration # :nodoc:
+ end
+
+ def self.inherited(subclass) # :nodoc:
+ super
+ if subclass.superclass == Migration
+ subclass.include Compatibility::Legacy
+ end
+ end
+
+ def self.[](version)
+ version = version.to_s
+ name = "V#{version.tr('.', '_')}"
+ unless Compatibility.const_defined?(name)
+ versions = Compatibility.constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete('V').tr('_', '.').inspect }
+ raise "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}"
+ end
+ Compatibility.const_get(name)
+ end
+
+ def self.current_version
+ Rails.version.to_f
+ end
MigrationFilenameRegexp = /\A([0-9]+)_([_a-z0-9]*)\.?([_a-z0-9]*)?\.rb\z/ # :nodoc: