aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/schema_dumper.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-12-03 04:57:04 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-12-03 05:01:41 +0900
commit01fb0907b2dafcecf63eedb80408d4cbff5f4d23 (patch)
tree4622fcd232d0c9af123a843de7f3c38d71e266f4 /activerecord/lib/active_record/schema_dumper.rb
parent6a7787218b8d75913b58d7bed198495e8d29e34e (diff)
downloadrails-01fb0907b2dafcecf63eedb80408d4cbff5f4d23.tar.gz
rails-01fb0907b2dafcecf63eedb80408d4cbff5f4d23.tar.bz2
rails-01fb0907b2dafcecf63eedb80408d4cbff5f4d23.zip
Refactor `length`, `order`, and `opclass` index options dumping
Diffstat (limited to 'activerecord/lib/active_record/schema_dumper.rb')
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 8cb2851557..16ccba6b6c 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -184,12 +184,12 @@ HEADER
"name: #{index.name.inspect}",
]
index_parts << "unique: true" if index.unique
- index_parts << "length: { #{format_options(index.lengths)} }" if index.lengths.present?
- index_parts << "order: { #{format_options(index.orders)} }" if index.orders.present?
+ index_parts << "length: #{format_index_parts(index.lengths)}" if index.lengths.present?
+ index_parts << "order: #{format_index_parts(index.orders)}" if index.orders.present?
+ index_parts << "opclass: #{format_index_parts(index.opclasses)}" if index.opclasses.present?
index_parts << "where: #{index.where.inspect}" if index.where
index_parts << "using: #{index.using.inspect}" if !@connection.default_index_type?(index)
index_parts << "type: #{index.type.inspect}" if index.type
- index_parts << "opclass: #{index.opclass.inspect}" if index.opclass.present?
index_parts << "comment: #{index.comment.inspect}" if index.comment
index_parts
end
@@ -232,6 +232,14 @@ HEADER
options.map { |key, value| "#{key}: #{value.inspect}" }.join(", ")
end
+ def format_index_parts(options)
+ if options.is_a?(Hash)
+ "{ #{format_options(options)} }"
+ else
+ options.inspect
+ end
+ end
+
def remove_prefix_and_suffix(table)
prefix = Regexp.escape(@options[:table_name_prefix].to_s)
suffix = Regexp.escape(@options[:table_name_suffix].to_s)