2015-04-02 47 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