diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-02-13 01:35:20 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-13 01:35:20 -0300 |
commit | e0d0dc6ec1ea9f690f2f354381c0ddf1c3c2ab0b (patch) | |
tree | 93e036d4454a9f8b96a73560250ac8bec57cff14 /activerecord/lib/active_record/connection_adapters | |
parent | 2f60a7525e8727f6c6d111637221b22898179fc5 (diff) | |
parent | 28dc6d76ab302340e98fad7f8718c440e5b1e2d8 (diff) | |
download | rails-e0d0dc6ec1ea9f690f2f354381c0ddf1c3c2ab0b.tar.gz rails-e0d0dc6ec1ea9f690f2f354381c0ddf1c3c2ab0b.tar.bz2 rails-e0d0dc6ec1ea9f690f2f354381c0ddf1c3c2ab0b.zip |
Merge pull request #26930 from kamipo/index_name_exists_default
The `default` arg of `index_name_exists?` makes to optional
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 13 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb | 7 |
2 files changed, 13 insertions, 7 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 e0528c1df6..c61aae85d3 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -773,11 +773,12 @@ module ActiveRecord end # Verifies the existence of an index with a given name. - # - # The default argument is returned if the underlying implementation does not define the indexes method, - # as there's no way to determine the correct answer in that case. - def index_name_exists?(table_name, index_name, default) - return default unless respond_to?(:indexes) + 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 @@ -1149,7 +1150,7 @@ module ActiveRecord validate_index_length!(table_name, index_name, options.fetch(:internal, false)) - if data_source_exists?(table_name) && index_name_exists?(table_name, index_name, false) + if data_source_exists?(table_name) && index_name_exists?(table_name, index_name) raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists" end index_columns = quoted_columns_for_index(column_names, options).join(", ") 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 a4b1723fc7..eebc688686 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -132,7 +132,12 @@ module ActiveRecord end # Verifies existence of an index with a given name. - def index_name_exists?(table_name, index_name, default) + 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) |