I am using the Octopus gem to do DB sharding in Rails.
How do I get the database connection specific to a shard. For example, I have a shard named "new_db" that I specified in my shards.yml. How do I get the db connection for it? The raw connection. I know how to update/insert to this shard, I just need the connection.
I tried the following with no avail. It just gives me the default connection I specified in my database.yml.
Octopus.using("new_db") do
connection = ActiveRecord::Base.connection
end
If you have this behavior:
It means that your connection is not established through Octopus.
You should have:
instead...
As momoshu pointed out in this GitHub issue, it might be caused by your app using
Other lead
I wasn't able to make it work because the gem was at the top of my gemfile, oddly, moving
gem 'ar-octopus'
to the bottom of the gemfile made it work.