This project is archived and is in readonly mode.

#5712 ✓stale
Zach Dennis

activerecord connection established event

Reported by Zach Dennis | September 27th, 2010 @ 02:42 AM

As a plugin author for enhanced ActiveRecord functionality it would be nice if establishing a database connection would fire an event. This would allow the plugin to know that an adapter has been loaded and for any adapter-specific functionality to be loaded.

Today, I updated activerecord-import to do just this because I can't load the functionality before the adapters load (and they are loaded as determined by Rails initialization or the user). This failed when using a Rails 3 app and keeping the auto-loading of Bundler dependencies in config/application.rb.

Another alternative is to have the user specifically load the adapter specific files after initialization. This is what I used to have users do, but it seems like an unnecessary step.

In the spirit of the load_hooks in Rails 3 I am currently wrapping the ActiveRecord::Base.establish_connection method so it calls fires a active_record_connection_established event via #run_load_hooks after a connection has been made. This allows me to pass the connection in. In my library's code all I have to do is listen for active_record_connection_established and then I can load library for the specific database adapter in use.

Here's a gist of the basic idea that I'm using in activerecord-import: http://gist.github.com/598480

I'm looking for some feedback before submitting a patch.

Comments and changes to this ticket

  • Zach Dennis

    Zach Dennis September 28th, 2010 @ 03:47 AM

    Mark VanHolstyn suggested today that having this a :before_connection_established event would better (or at least to have in addition to) what I requested above. I tend to agree. The :before_connection_established would fire off the event and allow plugins to modify the adapter before an adapter is established. This opens itself up for more possibilities of functionality since it provides a plugin library the ability to modify the connection adapter as needed in order to establish a connection.

  • David Trasbo

    David Trasbo October 10th, 2010 @ 06:16 PM

    • State changed from “new” to “open”
    • Importance changed from “” to “Low”

    +1

    Though I'd suggest it to be done through the new ActiveSupport::Notifications system.

  • Ryan Bigg

    Ryan Bigg October 19th, 2010 @ 08:23 AM

    • Tag cleared.

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages