2015-04-02 43 views
6

我需要設置一個持續集成流程,以使用Octopus Deploy將我們的應用程序作爲Azure雲服務進行部署。這個過程包括一個步驟,用於對我們的Azure SQL數據庫執行Entity Framework 6.1遷移(通過從本地八爪魚觸手運行migrate.exe)。但是,需要在Octopus機器上打開1433端口才能正常工作,而我們的管理員不會那樣做。在Octopus期間運行實體框架遷移將CI部署到Azure

在自動部署過程中執行Entity Framework遷移有什麼不同的建議嗎?

+0

你爲什麼不能打開端口?你決定做什麼? – 2015-08-25 21:17:17

回答

2

我們最終打開了該端口,因爲我們找不到任何其他解決方案。作爲參考,這裏是我們正在運行的腳本(我們的Deploy.ps1腳本,由NuGet在每個部署中執行)。

# 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 "content\migrate.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 
1

我上運行的應用程序的遷移開始使用此代碼:

class ApplicationDataContext : DbContext 
    { 
     internal static void UpdateDatabase() 
     { 
      Database.SetInitializer<ApplicationDataContext>(null); 

      var settings = new Migrations.Configuration(); 
      var migrator = new DbMigrator(settings); 
      migrator.Update(); 

     } 
} 
+0

您好@Serban,您是否在持續集成中使用它?如果是這樣,數據庫遷移問題是否會在部署過程中發現? – Ozzy 2016-01-24 17:12:54

+0

嘿@Ozzy, 是的,我正在做它作爲持續集成/部署的一部分。 – Serban 2016-01-25 12:00:48

+1

好的@Serban。但是,如果遷移失敗,您是否真的在部署過程中選擇異常,或者在構建和部署過程之後有人第一次實際運行應用程序時才選擇它? – Ozzy 2016-01-26 12:15:18