7

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?

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
marin
  • 523
  • 1
  • 6
  • 17

2 Answers2

2

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
marin
  • 523
  • 1
  • 6
  • 17
1

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();

        }
}
Murariu Serban
  • 95
  • 3
  • 11
  • Hi @Serban, are you using this in with Continuous Integration? If so, do DB migration issues get picked up by your deployment process? – Ozzy Jan 24 '16 at 17:12
  • Hey @Ozzy, Yes, I'm doing it as part of the continuous integration / deployment. – Murariu Serban Jan 25 '16 at 12:00
  • 1
    Okay @Serban. But do you actually pick up exceptions during the deploy if the migration fails, or do you only pick it up when somebody physically runs your application for the first time after the build and deploy process? – Ozzy Jan 26 '16 at 12:15
  • No, I don't. It's just when somebody runs the application for the first time (usually it's done by the person doing the deployment to check things are running smoothly). But what is it that you're trying to accomplish? It sounds to me like you could use a powershell script as one of the deployment steps if you want to run the migrations on deploy and rollback if things go south. – Murariu Serban Jan 31 '16 at 21:18