Heroku遵循:如何在Rails应用程序中处理多个数据库? [英] Heroku follow : how to handle multiple databases in a Rails app?
问题描述
我们在Heroku上托管了一个Rails应用程序,我需要为我们的营销人员设置一些分析页面。这似乎是Heroku的典型用例关注数据库
2个数据库将共享相同的模型类,我只想要一些操作来查询复制的数据库。
是在我的应用程序中处理这种情况的首选方法?
您也可以设置一个class-specific的连接,具体连接。例如,如果课程 我应该继承我所有的模型类来指定连接到辅助数据库吗? (它会工作吗?) 我也发现这个宝石,但它似乎不再维护.... magic_multi_connections gem ? 为了更好地回答这个问题:现在已经发布了一种使用八达通宝石处理这种情况的官方方式: https:// devcenter .heroku.com / articles / distribute-reads-to-followers-with-octopus 有了这个gem,可以创建一个完全复制的模型,或者只对追随者执行一个块: We have a Rails app hosted on Heroku and i need to set up some analytics pages for our marketing guy. This seems to be the typical use case for a Heroku follow database The 2 databases will share the same model classes, i want only some action to query the replicated database. What is the preferred way to handle this situation in my app ? ActiveRecord::Base documentation talks about class specific connection : You can also set a class-specific connection. For example, if Course
is an ActiveRecord::Base, but resides in a different database, you can
just say Course.establish_connection and Course and all of its
subclasses will use this connection instead. Should i subclass all my model classes to specify connection to a secondary database ? (will it even work ?) I also found this gem but it seems not maintained anymore.... magic_multi_connections gem ? To better answer this question : Heroku has now posted an "official" way of dealing with this situation using the Octopus gem : https://devcenter.heroku.com/articles/distributing-reads-to-followers-with-octopus With this gem it's possible to create either a fully replicated model, or execute only a block on the follower :
这篇关于Heroku遵循:如何在Rails应用程序中处理多个数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
是一个ActiveRecord :: Base,但驻留在不同的数据库中,则可以使用
仅说Course.establish_connection和Course,而其
的所有子类都将使用此连接。
$ b $ pre $ Octopus.using(:slave_two)做
User.create(: name =>Mike)
结束
Octopus.using(:slave_two) do
User.create(:name => "Mike")
end