EF Core (1.0.0) Migrations in Azure App Services

We have a web application (Net Core 1.0.0-preview2-003121) deployed to the Azure App Service, and we are trying to deploy the migration.

In RC1 / 2, you could perform migrations using the ef.cmd file, which seemed to be automatic, namely, we could use this file to run

dnx ef database update 

but it has disappeared.

dotnet ef not installed in the Azure App service itself, so this is not an option.

Any ideas that are not related to starting migration from code / deploying them from visual studio?

We are trying to create a continuous deployment pipeline, and I would rather avoid forcibly deploying migration from code.

MY google fu clearly fails because I cannot find anything and I cannot be the only one trying to deploy the migration to the server

TIA

+5
entity-framework azure
source share
1 answer

What we finished:

On the build side, we create an idempotent script database creation:

 dotnet ef migrations script --idempotent --output migrations.sql --context ApplicationContext 

Where ApplicationContext is the name of your EF context and migrations.sql is the name of the sql script file.

Then, on the deployment side, we have a small powershell script that effectively runs the migrations.sql script

 param( [Parameter(Mandatory)] [string]$server, [Parameter(Mandatory)] [string]$dbname, [Parameter(Mandatory)] [string]$dbadmin, [Parameter(Mandatory)] [string]$dbpassword, [Parameter(Mandatory)] [string]$migrationPath ) function Deploy-Migrations ($migrationPath,$DBSettings) { #Setting up database connection $connection = New-Object System.Data.SqlClient.SqlConnection $connection.ConnectionString = [string]::Format("Data Source=tcp:{0}.database.windows.net,1433;Initial Catalog={1};User Id={2}@{0};Password={3};MultipleActiveResultSets=True", $DBsettings['sqlServerName'], $DBsettings['databasename'],$DBsettings['adminAccount'], $DBsettings['adminPassword']) try { $connection.Open(); $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.Connection = $connection $query = Get-Content $migrationPath $sqlCmd.CommandText = $query.Replace("GO","") # This is required to prevent "syntax" complaints $sqlCmd.ExecuteNonQuery() Write-Host "Migration Deployed" } Catch { Write-Error "oops ... PAnic ... $($_.Exception.Message) on $($_.Exception.ItemName)" break } Finally { $connection.Close() } } $DBSettings = @{"sqlServerName"=$server; "databasename"=$dbname; "adminAccount"=$dbadmin; "adminPassword"=$dbpassword } Deploy-Migrations $migrationPath $DBSettings 
+2
source share

All Articles