London Calling

Ramblings of a software architect in London.

DotNetMigrations (DNM)

I’ve recently been trialling and contributing (work is still going on in a branch) on a small scale to a great little OSS project called DotNetMigrations. The GitHub site tells the full story, but essentially it allows you to write schema changes to your databases incrementally as you develop and automatically apply only the migrations you are missing if you are using an out-of-date database.

I’ve been working on making it very easy to integrate with existing projects by upgrading its NuGet installation. This is still a work in progress but the idea is that you can do the following:

1. Add DotNetMigrations to an application (web or windows/console etc.) using NuGet

2. A reference is added to DNM from your project, and the db.exe tool (that can be used to generate/run migrations standalone) is installed to your solution’s package folder

3. The required configuration (currently in appSettings keys) is added to the host application, this indicates the location of the migration scripts and the naming strategy

From that point on, as long as you sit in a command line that is inside the host application and reference the db.exe tool using a relative path, DNM will use your host application’s connectionStrings, completely integrating it.

For example you can then do commands like:

../../packages/DotNetMigrations-x.x.x/tools/db.exe generate "My first migration"

(to create a migration – you then open the generated file in any editor and add your schema change SQL)

../../packages/DotNetMigrations-x.x.x/tools/db.exe migrate myconnectionstringname

(to update the database pointed to by the connection string myconnectionstringname to the latest migration level)

Some future possibilities:

  • Including these calls as Powershell commands so that they can be run from within the NuGet Package Console, and to avoid having to use a separate command line and use awkward relative paths
  • Adding “auto migrate” logic to an application’s start-up code (optional) that will host the DNM core and upgrade databases on start-up to the required level
  • Along the same lines, should we be allowing people to package migrations as application resources?

Any thoughts or suggestions?

Leave a Reply

Your email address will not be published. Required fields are marked *