I am developing a sort of CMS application that will be used by
multiple domains on my host.
Each domain requires its own set of users, news, etc., but I would
like to keep my application only installed one place on my host and
sym-link to it.
Is it possible to modify all queries to also include a ‘domain’ in the
where clause or something like that?
i.e. if i do a Table.find(:all) in one of my controllers, and that
controller is being accessed by domain1, can I limit the query’s
results by some sort of where clause?
I dabbled with the idea of using table prefix’s, but later ditched the
idea.
It seems like the appropriate solution is to add another column to my
tables that includes which domain the data is specific to and somehow
limit that in the application… any ideas?
I’m no expert, but I have an application working that does the same
thing - and I can’t remember if it’s simlinked or we did some other
domain forwarding or what on the host to handle the multiple domain
names…
Hi Jay,
I’ve faced the same problem twice and once was for a project similar to
yours. There are essentially to ways: 1)a unique base code and a unique
db with a field identifying the customer in the tables; 2)a unique base
code and multiple databases (one per customer). For the CMS project I
followed the second way and the main problem is when you need to change
the DB structure but I think rake could help you a lot. Having faced
these problems and being working with PHP I then tried the first way but
I’ve to tell you that the development is much slower since almost each
query require to take in consideration the customer_id. Furthermore as
the db grows some queries get very slow so you have to tune them
carefully. Should you use a single DB you may consider partitioning the
DB which is available as of MySQL 5.1, that could help you make the
queries faster.
This is in summary my experience.
After finishing the second project I finally found a document with a in
depth discussion of these alternatives and … it’s published by M$,
here’s the link: Microsoft Learn: Build skills that open doors in your career
It might be useful to consider creating a different database instance
for each client/domain and simply customizing the database entries in
config/database.yml to suit. As I recall it is possible to place ruby
code in there so you may even be able to automate the the custom
configuration based on the incoming domain.
This also allows for clean separation of user data for backups, restores
and service termination.
It seems like the appropriate solution is to add another column to my
tables that includes which domain the data is specific to and somehow
limit that in the application… any ideas?
Have you looked into a combination of account_location and scope_out
plugins?
–
Roderick van Domburg
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.