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

fix(database_tasks): ConnectionPool deprecation warning in Rails 7.2 #341

Merged
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
16 changes: 8 additions & 8 deletions lib/data_migrate/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ module DatabaseTasks
extend self

# These method are only introduced in Rails 7.1
unless respond_to?(:with_temporary_connection_for_each)
def with_temporary_connection_for_each(env: ActiveRecord::Tasks::DatabaseTasks.env, name: nil, &block) # :nodoc:
unless respond_to?(:with_temporary_pool_for_each)
def with_temporary_pool_for_each(env: ActiveRecord::Tasks::DatabaseTasks.env, name: nil, &block) # :nodoc:
if name
db_config = ActiveRecord::Base.configurations.configs_for(env_name: env, name: name)
with_temporary_connection(db_config, &block)
with_temporary_pool(db_config, &block)
else
ActiveRecord::Base.configurations.configs_for(env_name: env, name: name).each do |db_config|
with_temporary_connection(db_config, &block)
with_temporary_pool(db_config, &block)
end
end
end

def with_temporary_connection(db_config) # :nodoc:
def with_temporary_connection(db_config, &block) # :nodoc:
with_temporary_pool(db_config) do |pool|
yield pool.connection
pool.with_connection(&block)
end
end

Expand All @@ -49,8 +49,8 @@ def migration_connection # :nodoc:
def db_configs_with_versions
db_configs_with_versions = Hash.new { |h, k| h[k] = [] }

with_temporary_connection_for_each do |conn|
db_config = conn.pool.db_config
with_temporary_pool_for_each do |pool|
db_config = pool.db_config
if db_config.primary?
versions_to_run = DataMigrate::DatabaseTasks.pending_data_migrations.map { |m| m[:version] }
target_version = ActiveRecord::Tasks::DatabaseTasks.target_version
Expand Down