I am designing a CRM using Ruby on Rails. How do you think, do I need a separate database for every client company? Or should I use the same database for everyone?
-
I'm pretty sure you don't. Why would you?Robin– Robin2012-09-06 18:38:43 +00:00Commented Sep 6, 2012 at 18:38
-
Every company would have its data in a separate database. More secure and faster.appplemac– appplemac2012-09-06 18:45:17 +00:00Commented Sep 6, 2012 at 18:45
-
Is it faster when you need to do JOIN queries as well?Robin– Robin2012-09-06 19:27:39 +00:00Commented Sep 6, 2012 at 19:27
-
Why would you need to JOIN data from separate companies?Raphael– Raphael2012-09-06 21:22:15 +00:00Commented Sep 6, 2012 at 21:22
2 Answers
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. 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. 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.
2 Comments
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.