diff options
author | Yves Senn <yves.senn@gmail.com> | 2013-11-26 09:58:24 +0100 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2013-11-26 10:03:55 +0100 |
commit | 6eba8d27e6feecca88303df6500ef6b376344e29 (patch) | |
tree | d84607e6b13721a4acd035a088a185b232bda0f3 /activerecord/lib/active_record | |
parent | e4c0a225ae029af91d26735d8085a09d6d64859e (diff) | |
download | rails-6eba8d27e6feecca88303df6500ef6b376344e29.tar.gz rails-6eba8d27e6feecca88303df6500ef6b376344e29.tar.bz2 rails-6eba8d27e6feecca88303df6500ef6b376344e29.zip |
`rename_index`: add the new index before removing the old one.
This prevents the following error when a MySQL index on a foreign key
column is renamed:
```
ActiveRecord::StatementInvalid: Mysql2::Error: Cannot drop index 'index_engines_on_car_id': needed in a foreign key constraint: DROP INDEX `index_engines_on_car_id` ON `engines`
```
refs: #13038.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 4b425494d0..6268ae4875 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -558,8 +558,8 @@ module ActiveRecord # this is a naive implementation; some DBs may support this more efficiently (Postgres, for instance) old_index_def = indexes(table_name).detect { |i| i.name == old_name } return unless old_index_def - remove_index(table_name, :name => old_name) - add_index(table_name, old_index_def.columns, :name => new_name, :unique => old_index_def.unique) + add_index(table_name, old_index_def.columns, name: new_name, unique: old_index_def.unique) + remove_index(table_name, name: old_name) end def index_name(table_name, options) #:nodoc: |