Skip to content

Conversation

@delphaber
Copy link
Contributor

Hello! Thanks for this gem :)

I'm wondering if you are interested into merging something like this. If so, I will try to add a test too.

Why do I think this method is useful?

Because I have a Rails application that uses multiple databases and I'm writing a rake task that wraps ruby-pg-extras and run the bloat command for each of our databases (5 databases at the moment).

Since the connection object is memoized, I'm not able to reset it after RubyPgExtras.database_url= as been called the first time. So, by being able to reset the connection, I'm able to call RubyPgExtras.database_url= multiple times, one for each database

What do you think? Is it something that you might consider?

@pawurb
Copy link
Owner

pawurb commented Jan 19, 2026

@delphaber hi, thanks for the PR! Sure, it's useful. But maybe you could include this reseting logic in database_url= instead?

@delphaber
Copy link
Contributor Author

I see. So, instead of having an explicit method to close the connection and nilify @_connection, we do it implicitly in database_url= method, like this

  def self.database_url=(value)
    @_connection&.close
    @_connection = nil
    @@database_url = value
  end

Have I understood it correctly?

Allows ruby-pg-extras to work with applications using multiple
databases (e.g. Rails sharding) by closing and clearing the
existing connection when database_url= is called.
@delphaber delphaber force-pushed the resettable_connection branch from f761d20 to a17d339 Compare January 20, 2026 14:59
@delphaber delphaber changed the title [WIP] Add ability to reset connection Add ability to reset connection Jan 20, 2026
@delphaber
Copy link
Contributor Author

Tests are passing locally

Finished in 0.33192 seconds (files took 0.06875 seconds to load)
145 examples, 0 failures

But need approval to run on CI

I hope this helps!

@pawurb pawurb merged commit 0c69a29 into pawurb:main Jan 20, 2026
6 checks passed
@pawurb
Copy link
Owner

pawurb commented Jan 20, 2026

thanks! It's released as 5.6.17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants