This post describes our process for developing databases with SQL Server Data Tools (SSDT) in Visual Studio.
For it to work, the conventions below must be respected.
- Use the live database as the gold standard for schema objects (and data).
- Deploy only database projects that have been built successfully.
- Deploy to a database that matches the schema of the live database.
At the beginning of a development iteration
- Restore a copy of the live database onto the development computer.
- Synchronise database project schema objects with the schema objects in the restored database.
- Remove pre-deployment and post-deployment scripts from the database project.
- Update the database project version number.
- Build the database project.
- If the build fails, fix the errors and rebuild.
- If the build completes, check in the changes.
During a development iteration
- Make changes to script files in the database project.
- If the changes might result in data loss, write pre-deployment and post-deployment scripts to migrate the data.
- Build the database project.
- If the build fails, fix the errors and rebuild.
- If the build succeeds, publish the changes onto the database on the development computer and test.
Interim releases to the test environment
- Restore a copy of the live database from backup.
- Build the database project.
- Publish the database project onto the test server.
Deployment to the live environment
- Back up the live database.
- Build the database project.
- Publish the database onto the live server.