7
votes

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?

2
why can't you open the PORT? What did you decided to do?Mark Evans

2 Answers

2
votes

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 "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
votes

I run the migrations on application start using this code:

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

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

        }
}