DB migration and Azure deployment slots

azurecontinuous-deliverydeploymententity-frameworkmigration

I'm planning to push a new web application to an Azure Web App Service (former Azure Website).
I'd like to make use of the deployment slots to be able to test my deployment before pushing it to production.
That's all fine as long as there is no DB schema change require. But if there is a schema change I can't have two software versions operating on the same db version.
Since I'm using EF Migrations, the push to the staging slot would instantly result in a DB update to the latest version.

So my question is, whether there is any use of deployment slots when a db migration is required?

How is it done for large SaaS providers. Are they performing a DB migration instantly with the new version? That would surely cause some downtime.

I can only think of rather complex solutions to this problem, is there anything simple?

Best Answer

Zero-downtime releases using Azure App Service slots and a single database shared by Staging and Production are possible - but you need to make sure that all database changes are backwards compatible, such that the current and new versions of the web app can run simultaneously in the Staging and production slots.

Some rules that ensure this works:

  • Any new database columns should be nullable or have default values
  • Renaming columns is not permitted
  • Dropping columns is not permitted

When you do need to make destructive changes, such as renaming or dropping columns, you need 2 releases to do this:

  1. The new version of the web app should be released, which removes the dependency on the renamed/dropped columns
  2. An additional release is made that performs the destructive changes

While this sounds a bit complicated, in practice you likely won't be making destructive changes very often.

Related Topic