Running Entity Framework migrations during Octopus Deploy CI to Azure
I need to set up a continuous integration process to deploy our application as an Azure cloud service, using Octopus Deploy. This process includes a step that executes Entity Framework 6.1 migrations against our Azure SQL database (by running migrate.exe
from the local Octopus tentacle). However, port 1433 would need to be opened on the Octopus machine for this to work, and our admin won't do that.
Is there a different way you can suggest for having Entity Framework migrations executed during the automated deploy process?
We ended up opening that port, as we couldn't find any other solution. For reference, here's the script we're running (our Deploy.ps1 script, executed by NuGet on each deployment).
# SOURCE: http://danpiessens.com/blog/2014/06/10/deploying-databases-with-octopus-deploy-part-2/
# Get the exe name based on the directory
$contentPath = (Join-Path $OctopusOriginalPackageDirectoryPath "content")
$fullPath = (Join-Path $OctopusOriginalPackageDirectoryPath "contentmigrate.exe")
Write-Host "Content Path:" $contentPath
Write-Host "Migrate Path:" $fullPath
cd $contentPath
write-host "Working Dir: "$(get-location)
# Run the migration utility
& "$fullPath" MyApp.Data.dll /startUpConfigurationFile=MyApp.Web.dll.config /connectionString=$ApplicationConnectionString /connectionProviderName="System.Data.SqlClient" /verbose | Write-Host
我使用以下代码在应用程序启动时运行迁移:
class ApplicationDataContext : DbContext
{
internal static void UpdateDatabase()
{
Database.SetInitializer<ApplicationDataContext>(null);
var settings = new Migrations.Configuration();
var migrator = new DbMigrator(settings);
migrator.Update();
}
}
链接地址: http://www.djcxy.com/p/25342.html
上一篇: 自动打开浏览器并登录到网站?