Filter migrations run based on Tags

kalenwatermeyer edited this page Mar 2, 2016 · 6 revisions
Clone this wiki locally

Scenario: multiple database once had the same schema but over the years have had differences introduced.

Because of this the majority of migrations, contained in one assembly, can be run against all the databases but at the same time you need to be able to filter certain migrations to run against specific databases based on the country (UK, DK, etc) and environment (Staging, Production, etc) it serves.

To facilitate this you can tag migrations (much like cucumber scenarios) and then filter these by passing tags into the runner. A migration is then run if it has:

  • No Tags
  • OR Has Tags that match ALL those passed into the runner.

Tags are assigned to migrations with an attribute/s:

[Tags("DK", "NL", "UK")]
[Tags("Staging", "Production")]
public class DoSomeStuffToEuropeanStagingAndProdDbs() { }

And the tags are entered into the command line like so: (Migrations with UK AND Production tags executed)

<migrate.exe command> --tag UK --tag Production

For the Nant and Msbuild runners, there is a Tags option and tags are passed in as a comma-separated string.


<Migrate Database="sqlserver2008"
         Tags="UK,Production" />


<migrate database="sqlserver2008"