mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Support Descending Indexes for MySQL
MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored. See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
This commit is contained in:
parent
1a92ae8318
commit
606830d27a
4 changed files with 14 additions and 4 deletions
|
@ -1,3 +1,10 @@
|
|||
* Support Descending Indexes for MySQL.
|
||||
|
||||
MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
|
||||
See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
|
||||
|
||||
*Ryuta Kamizono*
|
||||
|
||||
* Fix inconsistency with changed attributes when overriding AR attribute reader.
|
||||
|
||||
*bogdanvlviv*
|
||||
|
|
|
@ -90,10 +90,8 @@ module ActiveRecord
|
|||
true
|
||||
end
|
||||
|
||||
# Technically MySQL allows to create indexes with the sort order syntax
|
||||
# but at the moment (5.5) it doesn't yet implement them
|
||||
def supports_index_sort_order?
|
||||
true
|
||||
!mariadb? && version >= "8.0.1"
|
||||
end
|
||||
|
||||
def supports_transaction_isolation?
|
||||
|
|
|
@ -38,6 +38,7 @@ module ActiveRecord
|
|||
|
||||
indexes.last.columns << row[:Column_name]
|
||||
indexes.last.lengths.merge!(row[:Column_name] => row[:Sub_part].to_i) if row[:Sub_part]
|
||||
indexes.last.orders.merge!(row[:Column_name] => :desc) if row[:Collation] == "D"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -182,7 +182,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|||
if current_adapter?(:PostgreSQLAdapter)
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", order: { rating: :desc }', index_definition
|
||||
elsif current_adapter?(:Mysql2Adapter)
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", length: { type: 10 }', index_definition
|
||||
if ActiveRecord::Base.connection.supports_index_sort_order?
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", length: { type: 10 }, order: { rating: :desc }', index_definition
|
||||
else
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index", length: { type: 10 }', index_definition
|
||||
end
|
||||
else
|
||||
assert_equal 't.index ["firm_id", "type", "rating"], name: "company_index"', index_definition
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue