Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running update-database from Team City

I have created a new application using Entity Framework 4.3 database migrations. The migrations work great from the package manager console using the "update-database" command.

Now I want to run the database migrations every time the application is built using Team City, it looks like I need to create a powershell script that will do this.

Can anyone point me to some instructions on how to get the package manager commands to run from the command line, or powershell? All I can find is instructions on how to do this via the package manager console, which I don't know how to run from a Team City build step.

like image 861
moonpatrol Avatar asked Mar 26 '12 07:03

moonpatrol


2 Answers

migrate.exe is what I was looking for, it is found in "packages\EntityFramework.4.3.1\tools".

Add a new build step in Team City using:

Runner type: command line

Command executable: packages\EntityFramework.4.3.1\tools\migrate.exe

Command parameters: MyApplicationName /StartupDirectory:MyApplicationName\bin

like image 67
moonpatrol Avatar answered Oct 19 '22 19:10

moonpatrol


Install Entity Framework nuget to the repo and use the accompanying migrate.exe under packages\EntityFramework.5.0.0\tools\ or equivalent.

Then run a batch script like this:

SET AssemblyName=MyMvc4App
SET StartUpDirectory=MyMvc4App\bin\
SET ConnectionString=Server=tcp:XXXX.database.windows.net,1433;Database=XXXX;User ID=XXXX;Password=XXXX;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True
SET ConnectionStringProvider=System.Data.SqlClient
SET ConfigFilePath=%CD%\MyMvc4App\web.config
SET MigrateExe=packages\EntityFramework.5.0.0\tools\migrate.exe

%MigrateExe% %AssemblyName%.dll /startUpDirectory:%StartUpDirectory% /startUpConfigurationFile:"%ConfigFilePath%" /connectionProviderName:"%ConnectionStringProvider%" /connectionString:"%ConnectionString%" /verbose
pause

I answered a similar question and there I explain why I have yet to get it working without specifying a web/app.config file.

like image 45
angularsen Avatar answered Oct 19 '22 21:10

angularsen