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?
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
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With