diff options
author | Grey Baker <greysteil@gmail.com> | 2015-03-22 11:14:51 +0000 |
---|---|---|
committer | Grey Baker <greysteil@gmail.com> | 2015-12-15 17:36:09 +0000 |
commit | 9771f5e178ebc1b8c5a61f813373ca3b7bd983c8 (patch) | |
tree | 8b2c4d02f657c269b3935d6d764c6117f009b234 /activerecord/lib/active_record | |
parent | e73fe1dd8c2740ae29e7a7f48d71a62b46e6b49d (diff) | |
download | rails-9771f5e178ebc1b8c5a61f813373ca3b7bd983c8.tar.gz rails-9771f5e178ebc1b8c5a61f813373ca3b7bd983c8.tar.bz2 rails-9771f5e178ebc1b8c5a61f813373ca3b7bd983c8.zip |
Ignore index name in `index_exists?` when not passed a name to check for
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 11 |
2 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index b50d28862c..93f0d9d0e7 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -82,11 +82,10 @@ module ActiveRecord # def index_exists?(table_name, column_name, options = {}) column_names = Array(column_name).map(&:to_s) - index_name = options.key?(:name) ? options[:name].to_s : index_name(table_name, column: column_names) checks = [] - checks << lambda { |i| i.name == index_name } checks << lambda { |i| i.columns == column_names } checks << lambda { |i| i.unique } if options[:unique] + checks << lambda { |i| i.name == options[:name].to_s } if options[:name] indexes(table_name).any? { |i| checks.all? { |check| check[i] } } end diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index 4c8db8a2d5..bc5b97a711 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -28,6 +28,17 @@ module ActiveRecord options[:null] = true if options[:null].nil? super end + + def index_exists?(table_name, column_name, options = {}) + column_names = Array(column_name).map(&:to_s) + options[:name] = + if options.key?(:name).present? + options[:name].to_s + else + index_name(table_name, column: column_names) + end + super + end end class V4_2 < V5_0 |