Skip to content

Commit

Permalink
Do not enforce specific index names when changing column types
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Nov 17, 2023
1 parent 049b7f2 commit c77f430
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/online_migrations/change_column_type_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,17 +415,13 @@ def __copy_indexes(table_name, from_column, to_column)
end
end

# This is necessary as we can't properly rename indexes such as "taggings_idx".
if !index.name.include?(from_column)
raise "The index #{index.name} can not be copied as it does not " \
"mention the old column. You have to rename this index manually first."
if index.name.include?(from_column)
name = index.name.gsub(from_column, to_column)
end

name = index.name.gsub(from_column, to_column)

# Generate a shorter name if needed.
max_identifier_length = 63 # could use just `max_identifier_length` method for ActiveRecord >= 5.0.
name = index_name(table_name, new_columns) if name.length > max_identifier_length
name = index_name(table_name, new_columns) if !name || name.length > max_identifier_length

options = {
unique: index.unique,
Expand Down

0 comments on commit c77f430

Please sign in to comment.