Skip to content

Commit

Permalink
Support disallowing permanent connection checkouts with Rails 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuay03 committed Apr 5, 2024
1 parent 7678630 commit c6289f8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/immigrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,25 @@ def key_validator
end

def tables
@tables ||= ActiveRecord::Base.connection.tables
@tables ||= with_connection(&:tables)
end

def current_foreign_keys
tables.map{ |table|
ActiveRecord::Base.connection.foreign_keys(table)
}.flatten
with_connection do |connection|
tables.map{ |table|
connection.foreign_keys(table)
}.flatten
end
end

def with_connection
if ActiveRecord::VERSION::STRING >= '7.2'
ActiveRecord::Base.with_connection do |connection|
yield connection
end
else
yield ActiveRecord::Base.connection
end
end

def model_classes
Expand Down

0 comments on commit c6289f8

Please sign in to comment.