1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Deprecate passing default to index_name_exists?

This commit is contained in:
Ryuta Kamizono 2016-11-04 04:06:50 +09:00
parent 5e67187979
commit 28dc6d76ab
4 changed files with 21 additions and 5 deletions

View file

@ -1,3 +1,7 @@
* Deprecate passing `default` to `index_name_exists?`.
*Ryuta Kamizono*
* PostgreSQL: schema dumping support for interval and OID columns.
*Ryuta Kamizono*
@ -12,7 +16,7 @@
*namusyaka*
* Allow ActiveRecord::Base#as_json to be passed a frozen Hash.
* Allow `ActiveRecord::Base#as_json` to be passed a frozen Hash.
*Isaac Betesh*
@ -32,9 +36,9 @@
*Ryuta Kamizono*
* Fix `association_primary_key_type` for reflections with symbol primary key
* Fix `association_primary_key_type` for reflections with symbol primary key.
Fixes #27864
Fixes #27864.
*Daniel Colson*

View file

@ -774,6 +774,11 @@ module ActiveRecord
# Verifies the existence of an index with a given name.
def index_name_exists?(table_name, index_name, default = nil)
unless default.nil?
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing default to #index_name_exists? is deprecated without replacement.
MSG
end
index_name = index_name.to_s
indexes(table_name).detect { |i| i.name == index_name }
end

View file

@ -133,6 +133,11 @@ module ActiveRecord
# Verifies existence of an index with a given name.
def index_name_exists?(table_name, index_name, default = nil)
unless default.nil?
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing default to #index_name_exists? is deprecated without replacement.
MSG
end
table = Utils.extract_schema_qualified_name(table_name.to_s)
index = Utils.extract_schema_qualified_name(index_name.to_s)

View file

@ -31,8 +31,10 @@ module ActiveRecord
connection.add_index(table_name, [:foo], name: "old_idx")
connection.rename_index(table_name, "old_idx", "new_idx")
assert_not connection.index_name_exists?(table_name, "old_idx")
assert connection.index_name_exists?(table_name, "new_idx")
assert_deprecated do
assert_not connection.index_name_exists?(table_name, "old_idx", false)
assert connection.index_name_exists?(table_name, "new_idx", true)
end
end
def test_rename_index_too_long