Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Multidb should be initialized after ActiveRecord in Rails #1

Closed
wants to merge 2 commits into from

2 participants

@antage

When I try to use multidb with rails application I got following error:

ActiveRecord::ConnectionNotEstablished
/home/antage/workspace/app/.gems/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:167:in `connection_pool'
/home/antage/workspace/app/.gems/ruby/1.9.1/gems/ar-multidb-0.1.6/lib/multidb/configuration.rb:6:in `configure!'
/home/antage/workspace/app/.gems/ruby/1.9.1/gems/ar-multidb-0.1.6/lib/multidb.rb:12:in `install!'
/home/antage/workspace/app/.gems/ruby/1.9.1/gems/ar-multidb-0.1.6/lib/multidb.rb:28:in `<top (required)>'
/home/antage/workspace/app/.gems/ruby/1.9.1/gems/ar-multidb-0.1.6/lib/ar-multidb.rb:1:in `require'
/home/antage/workspace/app/.gems/ruby/1.9.1/gems/ar-multidb-0.1.6/lib/ar-multidb.rb:1:in `<top (required)>'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
/home/antage/workspace/app/config/application.rb:13:in `<top (required)>'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/antage/workspace/app/Rakefile:4:in `<top (required)>'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/rake_module.rb:25:in `load'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/rake_module.rb:25:in `load_rakefile'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:501:in `raw_load_rakefile'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:82:in `block in load_rakefile'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:81:in `load_rakefile'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:65:in `block in run'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/home/antage/.rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/home/antage/.rbenv/versions/1.9.3-p327/bin/rake:32:in `<main>'

It occurs due to multidb trying to get connection_pool before it's initialized.
I added lazy hook to ensure multidb extend activerecord after activerecord's initialized.

@atombender
Owner

Thanks for this. I need to make sure still works with Rails 2.3.15 (which we use with Multidb in production) before I can merge it.

@antage

This PR doesn't work with rails 2.3 and it seems multidb doesn't work with rails 3.x. Sorry I didn't find that information in README. Ignore this PR.

@antage antage closed this
@atombender
Owner

The intention is certainly to have it work with 3.x (most of our apps are on 3.2). I don't remember if I spent any work on it, but should be trivial to fix.

@atombender atombender reopened this
@atombender
Owner

I have changed how Multidb initializes to avoid explicit setup on startup. Instead, Multidb configures itself when it's first needed.

@atombender atombender closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2013
  1. @antage

    Better Rails support

    antage authored
  2. @antage
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 1 deletion.
  1. +9 −1 lib/multidb.rb
  2. +11 −0 lib/multidb/railtie.rb
View
10 lib/multidb.rb
@@ -17,6 +17,10 @@ def install!
end
@balancer = Balancer.new(@configuration)
end
+
+ def reconfigure!
+ @balancer = Balancer.new(@configuration)
+ end
attr_reader :balancer
@@ -25,4 +29,8 @@ def install!
end
end
-Multidb.install!
+if defined?(Rails) && Rails::VERSION::MAJOR >= 3
+ require 'multidb/railtie'
+else
+ Multidb.install!
+end
View
11 lib/multidb/railtie.rb
@@ -0,0 +1,11 @@
+require 'rails'
+
+module Multidb
+ class Railtie < Rails::Railtie
+ initializer 'multidb.active_record' do
+ ActiveSupport.on_load :active_record do
+ Multidb.install!
+ end
+ end
+ end
+end
Something went wrong with that request. Please try again.