instance method
rename_index
Ruby on Rails 8.0.4
Since v2.3.18Signature
rename_index(table_name, old_name, new_name)
Renames an index.
Rename the index_people_on_last_name index to index_users_on_last_name:
rename_index :people, 'index_people_on_last_name', 'index_users_on_last_name'
Parameters
-
table_namereq -
old_namereq -
new_namereq
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 983
def rename_index(table_name, old_name, new_name)
old_name = old_name.to_s
new_name = new_name.to_s
validate_index_length!(table_name, new_name)
# this is a naive implementation; some DBs may support this more efficiently (PostgreSQL, for instance)
old_index_def = indexes(table_name).detect { |i| i.name == old_name }
return unless old_index_def
add_index(table_name, old_index_def.columns, name: new_name, unique: old_index_def.unique)
remove_index(table_name, name: old_name)
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb line 983
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::SchemaStatements