Class: ActiveRecord::SchemaDumper
- Inherits:
-
Object
- Object
- ActiveRecord::SchemaDumper
- Defined in:
- lib/core_ext/active_record/schema_dumper.rb
Overview
Patched version: 3.1.3
- Patched methods
-
indexes
-
Instance Method Summary collapse
-
#indexes(table, stream) ⇒ Object
Writes out index-related details to the schema stream.
Instance Method Details
#indexes(table, stream) ⇒ Object
Writes out index-related details to the schema stream
Patch reason:
#indexes does not support writing out details related to partial indexes.
Patch:
Append :where clause if there’s a partial index
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/core_ext/active_record/schema_dumper.rb', line 15 def indexes(table, stream) if (indexes = @connection.indexes(table)).any? add_index_statements = indexes.map do |index| statement_parts = [ ('add_index ' + index.table.inspect), index.columns.inspect, (':name => ' + index.name.inspect), ] statement_parts << ':unique => true' if index.unique index_lengths = (index.lengths || []).compact statement_parts << (':length => ' + Hash[index.columns.zip(index.lengths)].inspect) unless index_lengths.empty? # Patch # Append :where clause if a partial index statement_parts << (':where => ' + index.where.inspect) if index.where statement_parts << (':using => ' + index.access_method.inspect) unless index.access_method.downcase == 'btree' ' ' + statement_parts.join(', ') end stream.puts add_index_statements.sort.join("\n") stream.puts end end |