Shahab
Shahab

Reputation: 822

Convert my already created application and database to support multiple sites on single db

I have created a custom CMS for one of my clients some years ago and developed it continuously. It has entities, entityGroups and a lot other tables and use LINQ2SQL to access data. I have 4 or 5 base classes who generate custom controls.

Recently, we came up with a need to create another website who use current website membership and authentication provider with same structure, but with different content.

It makes me think about using a single database to store both sites contents, but separate data by adding a field like ApplicationName to web.config of each site and content tables. Something like current design of default membership and roles providers of ASP.net.

But, I am not sure if it is the best solution. I want to know your advice on designing such system.

I want to minimize changes needed by this. For example, it would be more than nice if there be a way to set ApplicationID when creating database context (I create database contexts in my base class, so change would be in a single location), so there would be no need to change existing queries! Or, is there anyway to grab and fix queries just before they got send to database engine? These are my thoughts, do you have any other suggestion?

The question simply is: What is the best solution to use an existing database and application for multiple sites, with minimum changes and effort?

Upvotes: 3

Views: 121

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062745

If the sites are separate, I strongly suggest multiple databases; this will:

  • reduce risk of exposing the wrong data
  • allow more granular backups/maintenance
  • avoid excessively large db
  • allow you to remove sites cleanly when no longer needed
  • allow you to balance DBs (sites) between database servers
  • avoid compromising performance (adding an extra filter to every query ever written is a bad thing)
  • reduce the number of changes you need to make to the app

Basically, I would just have your central "GetConnection()" method worry about the multi-tenancy, serving the right connection for the site/config/user.

Hint: that's what we do here on stackoverflow/stackexchange

Upvotes: 3

Related Questions