Skip to main content

Migration Management

An environment variable must be selected for the project before a migration can be created. Environment variable selection is done using the following command sets. (For details of environment variables and Connection String management, see. Running the Web API Project)

(For Database Selection and Configuration, see. Database Selection and Configuration)

There are two types of environment variables for Migration Management with DevArchitecture;

  • Staging

  • Production

If migration will be made for the environment variables mentioned above, the following command examples are run after the selection is made.

$env:ASPNETCORE_ENVIRONMENT='Staging'

$env:ASPNETCORE_ENVIRONMENT='Production'

PostgreSql#

To run migration on PostgreSql, run the following commands respectively.

Migration via IDE#

If migration will be done via IDE, for example to Staging;

  1. If the WebAPI project is not defined, it is defined as Set as Startup Project by right-clicking on the project.

  1. The Package Manager Console screen opens from the Visual Studio 2019 View -> Other Windows menu.

  1. The Default Project DataAccess project is selected and the commands below are run on this screen.

$env:ASPNETCORE_ENVIRONMENT='Staging'

Add-Migration InitialCreate -Context ProjectDbContext -OutputDir Migrations/Pg

$env:ASPNETCORE_ENVIRONMENT='Staging'

Update-Database -context ProjectDbContext

Alternatively, migration via command line#

dotnet ef migrations add InitialCreate --context ProjectDbContext --output-dir Migrations/Pg

MsSql#

To run migration on Microsoft Sql Server, run the following commands respectively.

Migration via IDE#

If migration will be done via IDE, for example to Staging;

  1. If the WebAPI project is not defined, it is defined as Set as Startup Project by right-clicking on the project.

  1. The Package Manager Console screen opens from the Visual Studio 2019 View -> Other Windows menu.

  1. The Default Project DataAccess project is selected and the commands below are run on this screen.

$env:ASPNETCORE_ENVIRONMENT='Staging'

Add-Migration InitialCreate -context MsDbContext -OutputDir Migrations/Ms

$env:ASPNETCORE_ENVIRONMENT='Staging'

Update-Database -context MsDbContext

Alternatively, migration via command line#

dotnet ef migrations add InitialCreate --context MsDbContext --output-dir Migrations/Ms

Oracle#

To run migration on Oracle, run the following commands respectively.

Migration via IDE#

If migration will be done via IDE, for example to Staging;

  1. If the WebAPI project is not defined, it is defined as Set as Startup Project by right-clicking on the project.

  1. The Package Manager Console screen opens from the Visual Studio 2019 View -> Other Windows menu.

  1. The Default Project DataAccess project is selected and the commands below are run on this screen.

$env:ASPNETCORE_ENVIRONMENT='Staging'

Add-Migration InitialCreate -context OracleDbContext -OutputDir Migrations/Ora

$env:ASPNETCORE_ENVIRONMENT='Staging'

Update-Database -context MsDbContext

Alternatively, migration via command line#

dotnet ef migrations add InitialCreate --context OracleDbContext --output-dir Migrations/Ora

Not:#

Command fields marked with Red are the fields that are expected to be changed at each use.

The areas marked in Blue are the areas where optional changes are expected.

authors: Kerem VARIŞ, Veli GÖRGÜLÜ