Skip to content

Commit

Permalink
tentatively support mysql2 (pending a pull-request, really)
Browse files Browse the repository at this point in the history
  • Loading branch information
osheroff committed Mar 7, 2012
1 parent 07cecee commit 04218a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/active_record_host_pool/connection_adapter_mixin.rb
@@ -1,3 +1,6 @@
require 'active_record/connection_adapters/mysql_adapter'
require 'active_record/connection_adapters/mysql2_adapter' rescue nil

module ActiveRecordHostPool
module DatabaseSwitch
def self.included(base)
Expand Down Expand Up @@ -77,4 +80,7 @@ def establish_connection(name, spec)
end
end

ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval { include ActiveRecordHostPool::DatabaseSwitch }
["MysqlAdapter", "Mysql2Adapter"].each do |k|
next unless ActiveRecord::ConnectionAdapters.const_defined?(k)
ActiveRecord::ConnectionAdapters.const_get(k).class_eval { include ActiveRecordHostPool::DatabaseSwitch }
end
1 change: 0 additions & 1 deletion lib/active_record_host_pool/pool_proxy.rb
@@ -1,6 +1,5 @@
require 'delegate'
require 'active_record'
require 'active_record/connection_adapters/mysql_adapter'
require 'active_record_host_pool/connection_adapter_mixin'

# this module sits in between ConnectionHandler and a bunch of different ConnectionPools (one per host).
Expand Down

8 comments on commit 04218a3

@dasch
Copy link

@dasch dasch commented on 04218a3 Apr 11, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osheroff which pull request? :-D

It seems that Rails 3.2 is not too fond of mysql - explain, which is automatically called on slow queries, breaks:

undefined method `explain' for #<ActiveRecordHostPool::ConnectionProxy:0x133a847e0>

@osheroff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah.

Mysql2 dude accepted my pull-request. So if you use the HEAD of mysql2 and active_record_host_pool 0.6.1, you should be good to go.

@dasch
Copy link

@dasch dasch commented on 04218a3 Apr 12, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still doesn't run - it seems that mysql is being required in lib/active_record_host_pool/connection_adapter_mixin.rb.

/Users/dasch/.rvm/gems/ree-1.8.7-2011.03@global/gems/bundler-1.1.3/lib/bundler/rubygems_integration.rb:147:in `gem': mysql is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activerecord-3.2.2/lib/active_record/connection_adapters/mysql_adapter.rb:5
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/bundler/gems/active_record_host_pool-50d0b878aeb6/lib/active_record_host_pool/connection_adapter_mixin.rb:1
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/bundler/gems/active_record_host_pool-50d0b878aeb6/lib/active_record_host_pool/pool_proxy.rb:3
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/bundler/gems/active_record_host_pool-50d0b878aeb6/lib/active_record_host_pool.rb:6
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/config/environment.rb:5
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
    from /Users/dasch/Projects/help_center/config.ru:4
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/dasch/Projects/help_center/vendor/gems/ruby/1.8/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/dasch/Projects/help_center/config.ru:1:in `new'
    from /Users/dasch/Projects/help_center/config.ru:1

@osheroff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're running active_record_host_pool at the git sha of 50d0b87, but you need to be running the rubygems version @ 0.6.1

@dasch
Copy link

@dasch dasch commented on 04218a3 Apr 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still got the same problem - host_pool is trying to load the mysql gem, which is no longer present in my Gemfile.

@osheroff
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k, can you try bec2439 and see?

@dasch
Copy link

@dasch dasch commented on 04218a3 Apr 23, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried again, running ARHP 0.6.2, got this:

active_record_host_pool-0.6.2/lib/active_record_host_pool/connection_adapter_mixin.rb:64:in `_switch_connection': NoMethodError: undefined method `select_db' for #<Mysql2::Client:0x132a8fbc8>: select_db zendesk_development_shard_1 (ActiveRecord::StatementInvalid)

@dasch
Copy link

@dasch dasch commented on 04218a3 Apr 23, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to use the HEAD of mysql2 - it works now! Wunderbar!

Please sign in to comment.