Skip to content

Commit

Permalink
Merge pull request #2219 from koic/add_if_exists_to_remove_index
Browse files Browse the repository at this point in the history
Add `if_exists` option to `remove_index`
  • Loading branch information
yahonda authored Dec 21, 2021
2 parents c57bf7e + 59fb2ee commit d5115da
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ def add_index_options(table_name, column_name, comment: nil, **options) # :nodoc
# Remove the given index from the table.
# Gives warning if index does not exist
def remove_index(table_name, column_name = nil, **options) # :nodoc:
return if options[:if_exists] && !index_exists?(table_name, column_name, **options)

index_name = index_name_for_remove(table_name, column_name, options)
# TODO: It should execute only when index_type == "UNIQUE"
execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_column_name(index_name)}" rescue nil
Expand Down

0 comments on commit d5115da

Please sign in to comment.