Skip to content

Commit

Permalink
Merge pull request rsim#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 committed Dec 21, 2021
1 parent f40f021 commit 23081b3
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 23081b3

Please sign in to comment.