Skip to content

Commit

Permalink
Add if_exists option to remove_index
Browse files Browse the repository at this point in the history
Follow up to rails/rails#38967.

The `if_exists` option has been introduced since Rails 6.1.
  • Loading branch information
koic committed Dec 2, 2021
1 parent 0d74aa0 commit 59fb2ee
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 59fb2ee

Please sign in to comment.