Skip to content

Commit

Permalink
Reset state for lock timeout retries
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Nov 7, 2024
1 parent 425a651 commit eb0b67a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/strong_migrations/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ class << self

def initialize(migration)
@migration = migration
reset
end

def reset
@new_tables = []
@new_columns = []
@timeouts_set = false
@committed = false
@transaction_disabled = false
end

def self.safety_assured
Expand Down
2 changes: 1 addition & 1 deletion lib/strong_migrations/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def ddl_transaction(migration, ...)
# retry migration since the entire transaction needs to be rerun
checker.retry_lock_timeouts(check_committed: true) do
# failed transaction reverts timeout, so need to re-apply
checker.timeouts_set = false
checker.reset

super(migration, ...)
end
Expand Down
16 changes: 16 additions & 0 deletions test/timeouts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ def test_lock_timeout_retries_add_index
migrate AddIndexConcurrently, direction: :down
end

def test_lock_timeout_retries_add_index_safe_by_default
skip unless postgresql?

StrongMigrations.safe_by_default = true

assert_raises(ActiveRecord::LockWaitTimeout) do
with_lock_timeout_retries do
migrate AddIndex
end
end

migrate AddIndex, direction: :down
ensure
StrongMigrations.safe_by_default = false
end

def reset_timeouts
StrongMigrations.lock_timeout = nil
StrongMigrations.statement_timeout = nil
Expand Down

0 comments on commit eb0b67a

Please sign in to comment.