Commit 4cbc8c7747e86010b492d3871b6188e04634cbf4
1 parent
55a5a2a5
Exists in
master
and in
23 other branches
Forcing ordering of index statements in schema.rb
Showing
1 changed file
with
22 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
| 1 | +# based on https://rails.lighthouseapp.com/projects/8994/tickets/1266-order-add_index-statements-in-schemarb | ||
| 2 | +# only needed for rails < 2.2 | ||
| 3 | +if Rails::VERSION::STRING < "2.2.0" | ||
| 4 | + class ActiveRecord::SchemaDumper | ||
| 5 | + def indexes(table, stream) | ||
| 6 | + if (indexes = @connection.indexes(table)).any? | ||
| 7 | + | ||
| 8 | + add_index_statements = indexes.map do |index| | ||
| 9 | + statment_parts = [ ('add_index ' + index.table.inspect) ] | ||
| 10 | + statment_parts << index.columns.inspect | ||
| 11 | + statment_parts << (':name => ' + index.name.inspect) | ||
| 12 | + statment_parts << ':unique => true' if index.unique | ||
| 13 | + | ||
| 14 | + ' ' + statment_parts.join(', ') | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + stream.puts add_index_statements.sort.join("\n") | ||
| 18 | + stream.puts | ||
| 19 | + end | ||
| 20 | + end | ||
| 21 | + end | ||
| 22 | +end |