在Octopus Deploy CI到Azure期间运行实体框架迁移



我需要设置一个持续的集成过程,使用Octopus deploy将我们的应用程序部署为Azure云服务。此过程包括对我们的Azure SQL数据库执行Entity Framework 6.1迁移的步骤(通过从本地Octopus触手运行migrate.exe)。然而,需要在八达通机器上打开1433端口才能正常工作,我们的管理员不会这么做。

对于在自动化部署过程中执行实体框架迁移,您有没有其他建议?

我们最终打开了那个端口,因为我们找不到任何其他解决方案。作为参考,这是我们正在运行的脚本(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 "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();
        }
}

最新更新