diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-11-04 04:06:50 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-02-13 12:35:30 +0900 |
commit | 28dc6d76ab302340e98fad7f8718c440e5b1e2d8 (patch) | |
tree | eee792f3c08b74c7e13b640ee8dd7a0123c539de | |
parent | 5e67187979e56b9cad666abe40ca86a89f304f8f (diff) | |
download | rails-28dc6d76ab302340e98fad7f8718c440e5b1e2d8.tar.gz rails-28dc6d76ab302340e98fad7f8718c440e5b1e2d8.tar.bz2 rails-28dc6d76ab302340e98fad7f8718c440e5b1e2d8.zip |
Deprecate passing `default` to `index_name_exists?`
4 files changed, 21 insertions, 5 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 8e1ea7d023..8a1531e7ec 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -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* 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 54c4c62636..c61aae85d3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -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 diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index f9dffbe87b..eebc688686 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -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) diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb index 9223af5102..f10fcf1398 100644 --- a/activerecord/test/cases/migration/index_test.rb +++ b/activerecord/test/cases/migration/index_test.rb @@ -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 |