diff --git a/lib/immigrant.rb b/lib/immigrant.rb index bd00647..3b7be56 100644 --- a/lib/immigrant.rb +++ b/lib/immigrant.rb @@ -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 diff --git a/lib/immigrant/key_validator.rb b/lib/immigrant/key_validator.rb index 8adad2d..4377668 100644 --- a/lib/immigrant/key_validator.rb +++ b/lib/immigrant/key_validator.rb @@ -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