diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-11-19 15:33:20 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2019-01-03 15:12:49 +0100 |
commit | a39cddf7b78f71006c7b8884432efe41220becb6 (patch) | |
tree | e579e63cd8cf9bb92059a4bcdb8d13126aa360d2 /config | |
parent | 420442c5036b08652a758179d893bf8fe2b798ef (diff) | |
download | gitlab-ce-a39cddf7b78f71006c7b8884432efe41220becb6.tar.gz |
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
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/postgresql_opclasses_support.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/config/initializers/postgresql_opclasses_support.rb b/config/initializers/postgresql_opclasses_support.rb index 70b530415f5..b066f3788ec 100644 --- a/config/initializers/postgresql_opclasses_support.rb +++ b/config/initializers/postgresql_opclasses_support.rb @@ -130,9 +130,12 @@ module ActiveRecord where = inddef.scan(/WHERE (.+)$/).flatten[0] using = inddef.scan(/USING (.+?) /).flatten[0].to_sym opclasses = Hash[inddef.scan(/\((.+?)\)(?:$| WHERE )/).flatten[0].split(',').map do |column_and_opclass| - column, opclass = column_and_opclass.split(' ').map(&:strip) - [column, opclass] if opclass - end.compact] + 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 + end.compact] index_attrs = [table_name, index_name, unique, column_names, [], orders, where, nil, using, nil, opclasses] @@ -151,6 +154,9 @@ module ActiveRecord def quoted_columns_for_index(column_names, options = {}) column_opclasses = options[:opclasses] || {} 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 |