rails/rails — pull request #8645 by senny (2012-12-28 22:38:25+00:00)
Title: also rename indexes when a table or column is renamed

When a table or a column is renamed related indexes kept their name. This will lead to confusing names. This patch renames related indexes when a column or a table is renamed. Only indexes with names generated by rails will be renamed. Indexes with custom names will not be renamed.

I performed the following operations:

1. renamed argument `name` to `table_name` in `PostgresAdapter#rename_table`. I changed the name to make it consistent across the adapters and the API
1. `rename_table_indexes` and `rename_column_indexes` are available to rename related indexes. These methods are called from the individual adapters. I modified SQLite, MySQL and PostgreSQL

I noticed that the method to generated the name of an index is order dependent. This means that `index_name` will return a different name when the columns are passed in different order:

```ruby
index_name('articles', :column => ['a', 'b']) != index_name('articles', :column => ['b', 'a'])
```

This was problematic when implementing the rename for multi-column indexes. It works at the moment but the order dependent code could lead to indexes not being renamed. I would like to sort the columns before generating the name but this would have a bad impact on backwards compatibility because rails would generate different index names. Any ideas?