diff options
author | Jordi Bunster <jordi@bunster.org> | 2008-10-24 12:49:06 -0400 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-30 13:03:42 +0100 |
commit | a9e816843289d8839d4206c5ad09e49452d076ac (patch) | |
tree | 919bc69716c4b58d31b2f179304cf21c729f38ba | |
parent | 7418d367f0ac4a4ac0ab4604c1b10db78efc6865 (diff) | |
download | rails-a9e816843289d8839d4206c5ad09e49452d076ac.tar.gz rails-a9e816843289d8839d4206c5ad09e49452d076ac.tar.bz2 rails-a9e816843289d8839d4206c5ad09e49452d076ac.zip |
Ensure indices don't flip order in schema.rb [#1266 state:committed]
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/schema_dumper.rb | 18 |
2 files changed, 14 insertions, 6 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 06a290931c..4ca062b535 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *2.2.1 [RC2 or 2.2 final]* +* Ensure indices don't flip order in schema.rb #1266 [Jordi Bunster] + * Fixed that serialized strings should never be type-casted (i.e. turning "Yes" to a boolean) #857 [Andreas Korth] diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 4f96e225c1..2181bdf2dd 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -159,13 +159,19 @@ HEADER end def indexes(table, stream) - indexes = @connection.indexes(table) - indexes.each do |index| - stream.print " add_index #{index.table.inspect}, #{index.columns.inspect}, :name => #{index.name.inspect}" - stream.print ", :unique => true" if index.unique + if (indexes = @connection.indexes(table)).any? + add_index_statements = indexes.map do |index| + statment_parts = [ ('add_index ' + index.table.inspect) ] + statment_parts << index.columns.inspect + statment_parts << (':name => ' + index.name.inspect) + statment_parts << ':unique => true' if index.unique + + ' ' + statment_parts.join(', ') + end + + stream.puts add_index_statements.sort.join("\n") stream.puts end - stream.puts unless indexes.empty? end end -end +end
\ No newline at end of file |