简体   繁体   English

我是否需要在Ruby on Rails应用程序中使用多个数据库?

[英]Do I need to use multiple databases in Ruby on Rails application?

I am designing a CRM using Ruby on Rails. 我正在使用Ruby on Rails设计CRM。 How do you think, do I need a separate database for every client company? 您如何看待我是否需要为每个客户公司提供单独的数据库? Or should I use the same database for everyone? 或者我应该为每个人使用相同的数据库?

If they are separate companies or competing companies (for say a white label CRM) you'll most definitely want to run separate instances because then you can credibly claim total sandboxing. 如果他们是独立的公司或竞争公司(比如说白色标签CRM),你肯定会想要运行单独的实例,因为那时你可以可靠地声称总沙盒。 Otherwise, if you ever inadvertently wrote code that somehow allowed the data from one to display for the other, the game is over. 否则,如果你无意中编写的代码以某种方式允许一个数据显示另一个,则游戏结束。 Your customer will run for the hills and tell everyone about their terrible experience with your product. 您的客户将跑到山上,告诉每个人他们对您产品的糟糕体验。

I would even suggest you run separate instances of your app for each customer. 我甚至建议您为每个客户运行应用程序的单独实例。 Heroku provides a super simple way to deploy RoR apps so spinning up a new one whenever you add a new customer is a reasonable approach. Heroku提供了一种部署RoR应用程序的超级简单方法,因此无论何时添加新客户,都可以启动新的应用程序,这是一种合理的方法。 Of course, if you want a more turnkey solution that allows people to just sign up for an account, you will have to have a single instance that enforces customer data sandboxing in code. 当然,如果您想要一个允许人们只注册帐户的更具交钥匙的解决方案,您必须拥有一个实例来强制执行代码中的客户数据沙箱。 Obviously it can be done, but the separation isn't done at the infrastructure level which is ultimately the safest way. 显然它可以完成,但分离不是在基础设施层面完成的,这最终是最安全的方式。

Best regards. 最好的祝福。

I do it with a single database, like this: 我使用单个数据库,如下所示:

class Company < ActiveRecord::Base
  has_many :records

  def recent_records
   records.desc(:created_at)
  end
end

class Record < ActiveRecord::Base
  belongs_to :company
end 

Then, in the controller, I can write: 然后,在控制器中,我可以写:

@records = @company.recent_records

And pass that down to the views. 并将其传递给观点。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM