问题描述
我在Heroku上有一个多租户应用程序(多个帐户对彼此一无所知),我不确定如何最好地构建我的数据库。 Postgres的模式 ,但heroku无法很好地处理 。 p>
现在,我的Rails应用程序主要提供JSON,因为大多数模板都在渲染客户端(使用Backbone.js)。所以我正在考虑转向MongoDB,因为1)每个租户都可以获得一个顶级帐户文档,并且所有内容都可以嵌套在下面,并且2)其存储格式非常类似于JSON。我们仍处于测试阶段,因此可能会被取消。那些使用Mongo的有效理由是什么?前者甚至是使用Mongo的智能方式?
如果我坚持使用postgres,那么所有的东西都应该属于顶级Account模型(带索引)?如果是这样,我将如何处理连接?是否有可能执行多索引连接(总postgres noob)?
到目前为止,我们在一个表中有大约60k个条目,但是一个帐户可能只有200- 1000,所以我很担心加入整个桌子。
真的很感谢任何帮助。
更新:
我们最终转向了VPS(Rackspace Cloud)并实施了postgres的模式。对这一举动没有遗憾,因为它的运行速度比在Heroku上运行速度快得多,并且我们对服务器有更多的控制权。
查看这篇写于多重租赁的gem,其中包含postgres
I have a multi-tenant app on Heroku (multiple Accounts that know nothing about each other), and I'm unsure as how to best architect my database. Postgres's schemas look awesome, but heroku doesn't handle large numbers of them well.
Now, my Rails app is mainly serving JSON, as most of the templates are rendering client-side (using Backbone.js). So I'm considering moving to MongoDB because 1) each tenant could get one top level 'account' document, and everything could be nested below and 2) its storage format so closely resembles JSON. We are still in beta, so it could be pulled off. Are those valid reasons to use Mongo? Is former even an intelligent way to use Mongo?
If I were to stick with postgres, should everything belong_to the top level Account model (with indexes)? If so, how would I handle joins? Is it possible to perform mult-index joins (total postgres noob)?
We have about 60k entries in one table so far, yet a single account may only have 200-1000, so I'm worried about joining on the entire table.
Really appreciate any help.
Update:
We ended up moving to a VPS (Rackspace Cloud) and implementing postgres's schemas. No regrets with this move as it runs much faster than it did on Heroku, and we have more control of the server.
Check out this gem which was written to do multi-tenancy with postgres http://railscraft.tumblr.com/post/21421806379/multi-tenanting-ruby-on-rails-applications-on-heroku
这篇关于使用PostgreSQL的Heroku上的多租户Rails 3应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!