Hi,
I'm currently working on a SaaS type application, and for multi-tenancy I've settled on one database per user, with each database containing all tables required by the functionality the user is entitled to (have payed for). The application is designed to capture data (i.e. like web analytics) and present it for the user. The design should be able to scale to the tens of thousands of users (eventually).
Would a viable solution be to create the tables 'dynamically' when the application detects they are required? Or should I create all eventually required tables in specific user databases, as soon as I know they may be needed (user upgrade, new features, etc.)?
My current architecture would allow me to do something like this:
function insertData($table, $data) {
mysql_query("INSERT INTO ".$table." VALUES ('".implode("', '", $data)."')");
if ( mysql_errno() ) {
if (mysql_errno() == 1146) { // table does not exist
if ( $this->createTable($table) ) {
$this->insertData($table, $data)
}
} else {
// other errors
}
}
}
I would like the flexibility to be able to add functionality without having to loop through all user databases to add tables, so a setup like the above would help me achive that. But I'm not sure if I'm missing something that would make me regret the decision later?