1
votes

According to this, in rails 4, renaming a column will rename the index also.

class TestMigration < ActiveRecord::Migration
  def change
    binding.pry
    rename_column :feature_roles, :feature_id, :test_id
    binding.pry
  end
end

When I've listed the indices of this table before migration, the name of the particular index is index_feature_roles_on_feature_id and even after migration also, it remains the same. Why is it not updating to index_feature_roles_on_test_id?

I'm using Jruby 9.1.12.0 (ruby 2.3.3)

2
Check out the actual structure.sql diff. - ndnenkov
I'm using schema.rb and the corresponding entry after migration looks like: ``` add_index "feature_roles", ["test_id"], name: "index_feature_roles_on_feature_id", using: :btree ``` - Vijith mv
So the index changes, it's just that the name remains the same. - ndnenkov
yes. but later on, if I write a migration to remove the index by its name, it will fail - Vijith mv
It will work if you use the old name. - ndnenkov

2 Answers

0
votes

Probably the name of the index is not database generated, its what we give while creation of index in this case the name of the index wont get any update but definitely the reference will be updated and this will work the same way.

Still you want to update the index name you could drop index and recreate it.

DROP INDEX index_feature_roles_on_feature_id; 

post that recreate index on the updated column as

CREATE INDEX index_feature_roles_on_test_id ON feature_roles;

This could be helpful if in long run can be a case where several other developers might be working on the same thing which will remove the confusion.

0
votes

There is a potential bug in activerecord-jdbc-adapter gem. Check out the GitHub issue for details.