Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Migrations on CI Build Server

I run the migrations within Visual Studio's package manager. I am currently on the process of setting up a CI for our project. I was wondering how can you update the database from the CI (since you are not in the Visual Studio environment). Do I need to find a powershell.exe and execute that?

Ps. I am using Teamcity for CI.

like image 334
Karan Avatar asked Aug 02 '12 15:08

Karan


People also ask

How does EF migrations work?

EF Core compares the current model against a snapshot of the old model to determine the differences, and generates migration source files; the files can be tracked in your project's source control like any other source file. Once a new migration has been generated, it can be applied to a database in various ways.

How do I run down EF core migration?

Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.

What is EF core migration?

Migration is a way to keep the database schema in sync with the EF Core model by preserving data. As per the above figure, EF Core API builds the EF Core model from the domain (entity) classes and EF Core migrations will create or update the database schema based on the EF Core model.


1 Answers

You can use migrate.exe to migrate a database outside of the Visual Studio environment. It is located in the packages/EntityFramework.x.x.x/tools folder.

The tool has some rough edges that you'll need to be aware of.

  • Make sure EntityFramework.dll and migrate.exe are in the same directory
  • You'll probably need to specify the startUpDirectory parameter. Point it to the output directory of your application.

You can also write your own tools, the Update-Database command is backed by the Update method on DbMigrator.

like image 95
bricelam Avatar answered Sep 28 '22 07:09

bricelam