Migration runner
Migration runner is a tool to execute migration scripts on your target database. Use with:
- Command line
- MsBuild task
- Powershell Cmdlet
Command line
Execute DbVersionControl.MigrationRunner.exe with the following parameters:
- --Server (or -s) - Required. A server to run migration scripts
- --Database (or -d) - Required. Database name where migration scripts should be executed. A new database will be created if it does not exist
- --MigrationsFolderPath (or -f) - Required. A path to the migration scripts folder
- --Username (or -u) - Username to be used to connect to SQL Server. For SQL Authentication only
- --Password (or -p) - Password to be used to connect to SQL Server. For SQL Authentication only
-
--Variables (or -v) - Variables to be used in migration scripts using variableName=variableValue syntax. For example, to pass DataDirectory variable with value D:\Databases, you would specify:
-v DataDirectory=D:\Databases.
To pass multiple parameters, just add another parameter:
-v DataDirectory=D:\Databases Variable2=Value2
If your value contains spaces, quote the value, for example
-v DataDirectory="D:\Data bases" Variable2=Value2 - --ProjectFilePath - path to Database.sqlproj file to use variables from the project file automatically. If both --ProjectFilePath and --Variables are specified, the values are merged: first taken from Database.sqlproj and overridden with command line variables
MsBuild task
Import Migrations.MsBuild.targets file:
<Import Project="Path\to\Migrations.MsBuild.targets" />
To execute migrations, call MigrationRunner task with the following parameters (same as above):
- Server
- Database
- MigrationsFolderPath
- Username
- Password
- Variables
- ProjectFilePath
<ItemGroup>
<Variables Include="DataDirectory ">
<Value>D:\Data bases</Value>
</Variables>
<Variables Include="Variable2">
<Value>Value2</Value>
</Variables>
</ItemGroup>
<MigrationRunner
Server="$(server)"
Database="$(database)"
MigrationsFolderPath="$(migrationsFolderPath)"
Username="$(username)"
Password="$(password)"
Variables="@(Variables)"
ProjectFilePath="Path\To\Database.sqlproj"
/>
Powershell cmdlet
First, import MigrationRunner cmdlet from Migrations.dll:
import-module .\Migrations.dll
Next, execute Get-MigrationRunner with the following parameters:
- -Server (or -s) - Required. A server to run migration scripts
- -Database (or -d) - Required. Database name where migration scripts should be executed. A new database will be created if it does not exist
- -MigrationsFolderPath (or -f) - Required. A path to the migration scripts folder
- -Username (or -u) - Username to be used to connect to SQL Server. For SQL Authentication only
- -Password (or -p) - Password to be used to connect to SQL Server. For SQL Authentication only
-
-Variables (or -v) - Variables to be used in migration scripts using variableName=variableValue syntax. For example, to pass DataDirectory variable with value D:\Databases, you would specify:
-v "DataDirectory=D:\Databases".
To pass multiple parameters, separate with a comma:
-v "DataDirectory=D:\Databases","Variable2=Value2"
If your value contains spaces, the syntax is the same:
-v "DataDirectory=D:\Data bases","Variable2=Value2" - -ProjectFilePath - path to Database.sqlproj file to use variables from the project file automatically. If both -ProjectFilePath and -Variables are specified, the values are merged: first taken from Database.sqlproj and overridden with command line variables