Skip to content

Commit

Permalink
Improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Nov 9, 2024
1 parent 397b831 commit 0c78b28
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/strong_migrations/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ def perform(method, *args, &block)
def perform_method(method, *args)
if StrongMigrations.remove_invalid_indexes && direction == :up && method == :add_index && postgresql?
@skip_retries = true
options = args.extract_options!
remove_invalid_index_if_needed(*args, **options)
remove_instance_variable(:@skip_retries)
begin
remove_invalid_index_if_needed(*args)
ensure
remove_instance_variable(:@skip_retries)
end
end
yield
end
Expand Down Expand Up @@ -246,7 +248,9 @@ def retry_lock_timeouts?(method)
end

# REINDEX INDEX CONCURRENTLY leaves a new invalid index if it fails, so use remove_index instead
def remove_invalid_index_if_needed(*args, **options)
def remove_invalid_index_if_needed(*args)
options = args.extract_options!

# ensures has same options as existing index
# check args to avoid errors with index_exists?
return unless args.size == 2 && connection.index_exists?(*args, **options.merge(valid: false))
Expand Down

0 comments on commit 0c78b28

Please sign in to comment.