Which is the best way to handle multi-user applications in Rails
Let me try to explain what I am trying to do:
I wrote an application and sold it to different companies. For every
company I sold the
app to, I deployed a fresh Rails app to a fresh 256MB VPS and provided
account (to the app, not the server).
Customers handle their own users from there as they see fit. User
handled by a combination of acts_as_authenticated, a recipe from Chad
Recipes and a handful of rather ugly hacks. All in all, user
administration is very
complex since a superuser has very fine-grained control over which
parts of the
application and database operations and records a regular user can
have access to.
I want to rewrite the whole thing from the ground up and one of the
changes will be to have only one code base shared by all users. (Maybe
this is the
way it should have been deployed in the first place but given my lack
and the fact that my customer base is very very small -think dozens,
multiple deployments were a good idea at the time).
Problem is, I am not exactly sure how to go about that:
First, it will add another layer of complexity to the user
administration system and I still
have to figure out how to handle it.
And what about the database?, should all companies and thus, users,
share the same one?
That worries me a bit considering:
a) Users of my system are direct competitors and the information
contained in the database
b) Although traffic is not a concern at all, the database can grow
considerably large in a short
period of time.
c) If the database crashes ALL my customers will be affected, not
just one. Granted, I really
should backup regularly but still…
Is there a way to have multiple connections to different databases and
decide which database
to query given the user that has just accessed the app? If so, is that
a good idea?