Reputation: 187
Question:
I am creating an Asp.Net application that has a multi-tenant data architecture with separate databases for each tenant. I need to be able to create and deploy databases programmatically from the application when a new tenant signs up. What is the best way to maintain a template database/schema/script and use it to deploy a new database on the server.
Note:
I am using .Net 4.0 for the application and SQL Server 2008 R2 for the server.
Current Workaround:
Currently a default template database is maintained on the server. Changes to the database are done through Visual Studio to maintain versioning through source control. When a new database needs to be deployed:
Create a new database on the server using Database.Create.
Then use Transfer.TransferData to transfer just the schema over to the new database. Or, use Transfer.ScriptTransfer and store the script in memory for subsequent deployments.
Upvotes: 2
Views: 769
Reputation: 294407
Your deployment should be based on scripts that create the database from scratch. Any schema modification you make, make it through a script that upgrades the database schema. See Version Control and Your Database for a more extended discussion of the topic.
The alternative of doing diff tools based deployment put you at the mercy of the tools decision on how to handle the diff (with large tables, this can get very dangerous if the tool decided to to a copy-based modification) and also puts you at the mercy of whatever support the diff tool has for automation, which makes the failure/retry handling, how should I put it,... 'fun'.
Upvotes: 2