Skip to content

Commit

Permalink
Merge pull request #26689 from kamipo/deprecate_passing_name_to_indexes
Browse files Browse the repository at this point in the history
Deprecate passing `name` to `indexes` like `tables`
  • Loading branch information
rafaelfranca committed Jan 4, 2017
2 parents 0df8649 + 457e6c7 commit fdc219e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
* Deprecate passing `name` to `indexes`.

*Ryuta Kamizono*

* Remove deprecated tasks: `db:test:clone`, `db:test:clone_schema`, `db:test:clone_structure`.

*Rafel Mendonça França*

* Compare deserialized values for `PostgreSQL::OID::Hstore` types when
calling `ActiveRecord::Dirty#changed_in_place?`
calling `ActiveRecord::Dirty#changed_in_place?`.

Fixes #27502.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def view_exists?(view_name)
end

# Returns an array of indexes for the given table.
# def indexes(table_name, name = nil) end
def indexes(table_name, name = nil)
raise NotImplementedError, "#indexes is not implemented"
end

# Checks to see if an index exists on a table for a given index definition.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ def truncate(table_name, name = nil)

# Returns an array of indexes for the given table.
def indexes(table_name, name = nil) #:nodoc:
if name
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing name to #indexes is deprecated without replacement.
MSG
end

indexes = []
current_index = nil
execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ def index_name_exists?(table_name, index_name, default)
end

# Returns an array of indexes for the given table.
def indexes(table_name, name = nil)
def indexes(table_name, name = nil) # :nodoc:
if name
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing name to #indexes is deprecated without replacement.
MSG
end

table = Utils.extract_schema_qualified_name(table_name.to_s)

result = query(<<-SQL, "SCHEMA")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ def new_column_from_field(table_name, field) # :nondoc:

# Returns an array of indexes for the given table.
def indexes(table_name, name = nil) #:nodoc:
if name
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing name to #indexes is deprecated without replacement.
MSG
end

exec_query("PRAGMA index_list(#{quote_table_name(table_name)})", "SCHEMA").map do |row|
sql = <<-SQL
SELECT sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_tables_logs_name
end

def test_indexes_logs_name
@connection.indexes("items", "hello")
assert_deprecated { @connection.indexes("items", "hello") }
assert_equal "SCHEMA", @subscriber.logged[0][1]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_tables_logs_name
def test_indexes_logs_name
with_example_table do
assert_logged [["PRAGMA index_list(\"ex\")", "SCHEMA", []]] do
@conn.indexes("ex", "hello")
assert_deprecated { @conn.indexes("ex", "hello") }
end
end
end
Expand Down

0 comments on commit fdc219e

Please sign in to comment.