Skip to content
This repository
Browse code

Ensure indices don't flip order in schema.rb [#1266 state:committed]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information...
commit a9e816843289d8839d4206c5ad09e49452d076ac 1 parent 7418d36
Jordi Bunster authored October 24, 2008 dhh committed October 30, 2008
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *2.2.1 [RC2 or 2.2 final]*
2 2
 
  3
+* Ensure indices don't flip order in schema.rb #1266 [Jordi Bunster]
  4
+
3 5
 * Fixed that serialized strings should never be type-casted (i.e. turning "Yes" to a boolean) #857 [Andreas Korth]
4 6
 
5 7
 
18  activerecord/lib/active_record/schema_dumper.rb
@@ -159,13 +159,19 @@ def default_string(value)
159 159
       end
160 160
       
161 161
       def indexes(table, stream)
162  
-        indexes = @connection.indexes(table)
163  
-        indexes.each do |index|
164  
-          stream.print "  add_index #{index.table.inspect}, #{index.columns.inspect}, :name => #{index.name.inspect}"
165  
-          stream.print ", :unique => true" if index.unique
  162
+        if (indexes = @connection.indexes(table)).any?
  163
+          add_index_statements = indexes.map do |index|
  164
+            statment_parts = [ ('add_index ' + index.table.inspect) ]
  165
+            statment_parts << index.columns.inspect
  166
+            statment_parts << (':name => ' + index.name.inspect)
  167
+            statment_parts << ':unique => true' if index.unique
  168
+
  169
+            '  ' + statment_parts.join(', ')
  170
+          end
  171
+
  172
+          stream.puts add_index_statements.sort.join("\n")
166 173
           stream.puts
167 174
         end
168  
-        stream.puts unless indexes.empty?
169 175
       end
170 176
   end
171  
-end
  177
+end

0 notes on commit a9e8168

Please sign in to comment.
Something went wrong with that request. Please try again.