DbUp is an open source .Net library that helps making database changes in a deployment an awful lot easier.
The docs for DbUp can be found here, however DbUp is so easy to use there isn’t much to them.
Setup
First thing to do in order to get DbUp working is to start a new console application then install the DbUp nuget package.
Install-Package DbUp
Any SQL scripts that you want to be run as part of the application need to be added to the project and set their build action to be an embedded resource. While DbUp keeps a track of the scripts it has run, I find it useful to name the scripts sequentially to help keep them organised.
In Program.cs you will need to add the code from the docs and then you are ready to run the console application. There is a debug conditional in the code with a Console.ReadLine() if there is a failure in the application so you can see the error message. It’s probably me being overly cautious but I also like to put the same debug conditional in for successes as well just so I can review those messages if needs be.
For deployments, all you need to do is run the console application in each environment by using a Powershell script for example.
Benefits
Just as automated code deployments are important, it’s also important to automate database changes. As its likely that database changes are less common that code changes, it can be very easy to forget to make any required changes if they have to be done manually.
While there are other tools such as Redgate’s SQL Compare and they are awesome, for keeping a database in a correct state for deployments I’m a big fan of DbUp. Rather than just comparing two databases I like to be in control of the changes and write my own scripts.
Another very useful benefit of this approach is that the database scripts can be stored in source control.
Given that DbUp is free and so easy to setup then I think this is a great tool to be part of deployments.