Magic Multi-Connectionsという分散DB対応ライブラリがあることをいまごろ知ったので簡単に試してみる。 とても分かりやすい記事があったので使わせていただきます。 想定として、Userモデル、UserInfoモデルがあり、 Userはメインデータベースで管理する。 UserInfoはユーザ別のSQLite3ファイルで管理する。 というケース*1。 コネクションの切り替えは、試しにAR::Baseにメソッド [] を追加してみた。 これで UserInfo[user.id].find :all と、[]にコネクション識別値を渡して切り替えができる。 以下、サンプルコード。 require "rubygems" require "fileutils" require "active_record" require "magic_multi_connections" Activ