aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration/compatibility.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/migration/compatibility.rb')
-rw-r--r--activerecord/lib/active_record/migration/compatibility.rb75
1 files changed, 36 insertions, 39 deletions
diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb
index 74833f938f..2904634eb7 100644
--- a/activerecord/lib/active_record/migration/compatibility.rb
+++ b/activerecord/lib/active_record/migration/compatibility.rb
@@ -5,7 +5,7 @@ module ActiveRecord
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 }
+ 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)
@@ -13,7 +13,27 @@ module ActiveRecord
V5_1 = Current
- module FourTwoShared
+ class V5_0 < V5_1
+ def create_table(table_name, options = {})
+ if adapter_name == "PostgreSQL"
+ if options[:id] == :uuid && !options[:default]
+ options[:default] = "uuid_generate_v4()"
+ end
+ end
+
+ # Since 5.1 Postgres adapter uses bigserial type for primary
+ # keys by default and MySQL uses bigint. This compat layer makes old migrations utilize
+ # serial/int type instead -- the way it used to work before 5.1.
+ if options[:id].blank?
+ options[:id] = :integer
+ options[:auto_increment] = true
+ end
+
+ super
+ end
+ end
+
+ class V4_2 < V5_0
module TableDefinition
def references(*, **options)
options[:index] ||= false
@@ -21,7 +41,7 @@ module ActiveRecord
end
alias :belongs_to :references
- def timestamps(*, **options)
+ def timestamps(**options)
options[:null] = true if options[:null].nil?
super
end
@@ -59,7 +79,7 @@ module ActiveRecord
end
alias :add_belongs_to :add_reference
- def add_timestamps(*, **options)
+ def add_timestamps(_, **options)
options[:null] = true if options[:null].nil?
super
end
@@ -83,46 +103,23 @@ module ActiveRecord
private
- def index_name_for_remove(table_name, options = {})
- index_name = index_name(table_name, options)
+ def index_name_for_remove(table_name, options = {})
+ index_name = index_name(table_name, options)
+
+ unless index_name_exists?(table_name, index_name, true)
+ if options.is_a?(Hash) && options.has_key?(:name)
+ options_without_column = options.dup
+ options_without_column.delete :column
+ index_name_without_column = index_name(table_name, options_without_column)
- unless index_name_exists?(table_name, index_name, true)
- if options.is_a?(Hash) && options.has_key?(:name)
- options_without_column = options.dup
- options_without_column.delete :column
- index_name_without_column = index_name(table_name, options_without_column)
+ return index_name_without_column if index_name_exists?(table_name, index_name_without_column, false)
+ end
- return index_name_without_column if index_name_exists?(table_name, index_name_without_column, false)
+ raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
end
- raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
+ index_name
end
-
- index_name
- end
- end
-
- class V5_0 < V5_1
- end
-
- class V4_2 < V5_0
- # 4.2 is defined as a module because it needs to be shared with
- # Legacy. When the time comes, V5_0 should be defined straight
- # in its class.
- include FourTwoShared
- end
-
- module Legacy
- include FourTwoShared
-
- def migrate(*)
- ActiveSupport::Deprecation.warn \
- "Directly inheriting from ActiveRecord::Migration is deprecated. " \
- "Please specify the Rails release the migration was written for:\n" \
- "\n" \
- " class #{self.class.name} < ActiveRecord::Migration[4.2]"
- super
- end
end
end
end