After_connect hook in Active Record


I want to execute some SQL after the connection has been established
example SELECT set_limit(0.2) to set the trigram match threshold in
PostgreSQL). I’m looking for something like after_connect hook but
found one.

I could monkey-patch Active Record but I’d prefer a more elegant
I could execute the code from an initializer but it won’t work if the
connection needs to be reestablished.

My question is: what’s the best way to execute a piece of code for each
newly established Active Record connection?

Best regards

Greg Navis
I help tech companies to scale Heroku-hosted Rails apps.
Free, biweekly scalability newsletter for SaaS CEOs

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs