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 82c0889
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 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
6 changes: 5 additions & 1 deletion lib/immigrant/key_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ def columns_for(table_name)
end

def connection
@connection ||= ActiveRecord::Base.connection
@connection ||= if ActiveRecord::VERSION::STRING >= '7.2'
ActiveRecord::Base.lease_connection
else
ActiveRecord::Base.connection
end
end
end
end

0 comments on commit 82c0889

Please sign in to comment.