Commit a39cddf7 authored by Andreas Brandl's avatar Andreas Brandl

Add support for explicit index order

ActiveRecord supports `:order` natively, but it is skipped because of
our specific patch to support opclasses.

Relevant AR code:
https://github.com/rails/rails/blob/5-0-stable/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L1167
parent 420442c5
...@@ -131,6 +131,9 @@ module ActiveRecord ...@@ -131,6 +131,9 @@ module ActiveRecord
using = inddef.scan(/USING (.+?) /).flatten[0].to_sym using = inddef.scan(/USING (.+?) /).flatten[0].to_sym
opclasses = Hash[inddef.scan(/\((.+?)\)(?:$| WHERE )/).flatten[0].split(',').map do |column_and_opclass| opclasses = Hash[inddef.scan(/\((.+?)\)(?:$| WHERE )/).flatten[0].split(',').map do |column_and_opclass|
column, opclass = column_and_opclass.split(' ').map(&:strip) column, opclass = column_and_opclass.split(' ').map(&:strip)
end.reject do |column, opclass|
['desc', 'asc'].include?(opclass&.downcase)
end.map do |column, opclass|
[column, opclass] if opclass [column, opclass] if opclass
end.compact] end.compact]
...@@ -151,6 +154,9 @@ module ActiveRecord ...@@ -151,6 +154,9 @@ module ActiveRecord
def quoted_columns_for_index(column_names, options = {}) def quoted_columns_for_index(column_names, options = {})
column_opclasses = options[:opclasses] || {} column_opclasses = options[:opclasses] || {}
column_names.map {|name| "#{quote_column_name(name)} #{column_opclasses[name]}"} column_names.map {|name| "#{quote_column_name(name)} #{column_opclasses[name]}"}
quoted_columns = Hash[column_names.map { |name| [name.to_sym, "#{quote_column_name(name)} #{column_opclasses[name]}"] }]
add_options_for_index_columns(quoted_columns, options).values
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment