Skip to content

Commit

Permalink
fix: ConnectionPool deprecation warning in Rails 7.2
Browse files Browse the repository at this point in the history
Fixes this deprecation warning raised in Rails 7.2:

```
DEPRECATION WARNING: ActiveRecord::ConnectionAdapters::ConnectionPool#connection is deprecated
and will be removed in Rails 8.0. Use #lease_connection instead.
```

The changed code is simply copied from the Rails repository, please see
https://github.com/rails/rails/blob/97169912f197eee6e76fafb091113bddf624aa67/activerecord/lib/active_record/tasks/database_tasks.rb#L520
and
https://github.com/rails/rails/blob/97169912f197eee6e76fafb091113bddf624aa67/activerecord/lib/active_record/tasks/database_tasks.rb#L550
  • Loading branch information
martingregoire authored and vprigent committed Oct 8, 2024
1 parent 9d5b936 commit 9cb2d8b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/data_migrate/database_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def with_temporary_connection_for_each(env: ActiveRecord::Tasks::DatabaseTasks.e
end
end

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

Expand All @@ -36,13 +36,13 @@ def migration_connection # :nodoc:
migration_class.connection
end

private def with_temporary_pool(db_config)
private def with_temporary_pool(db_config, clobber: false)
original_db_config = migration_class.connection_db_config
pool = migration_class.connection_handler.establish_connection(db_config)
pool = migration_class.connection_handler.establish_connection(db_config, clobber: clobber)

yield pool
ensure
migration_class.connection_handler.establish_connection(original_db_config)
migration_class.connection_handler.establish_connection(original_db_config, clobber: clobber)
end
end

Expand Down

0 comments on commit 9cb2d8b

Please sign in to comment.