Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support disallowing permanent connection checkouts with Rails 7.2 #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::Base.respond_to?(:with_connection)
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::Base.respond_to?(:lease_connection)
ActiveRecord::Base.lease_connection
else
ActiveRecord::Base.connection
end
end
end
end