9
votes

I'm trying to achieve zero downtime deployments of an Azure web app where database schema updates need to be applied as part of the deployment.

I have the following setup:

Production web app with production-db connection string.

Staging deployment slot with staging-db connection string.

My pseudo-deployment process is something like:

  1. Make a copy of the production-db database
  2. Configure the Staging slot to use the database copy
  3. Deploy code to the Staging slot
  4. Apply schema updates to the database copy
  5. Test-run the app in the Staging slot (with the updated database) and pre-warm it
  6. If everything works, perform a hot swap so that the pre-warmed app in the Staging slot goes live, i.e. becomes the production slot, still using the updated database

In other words, after the hot swap, I want both the new code and the updated database to be live.

If something goes wrong at this point, I can simply swap slots again, making the old production app (and its database) go live.

As I understand it now, when I swap slots, the app will use the connection string of the production slot, restarting the app and forcing me to apply the database schema updates after the updated code goes live.

I hope I'm describing this properly. :) This seems like it should be a fairly common scenario?

Any help or pointers are greatly appreciated!

PS. I've looked at Azure seamless upgrade when database schema changes, but that answer isn't valid, as I can't apply the schema updates without affecting the application.

Edit: Just a thought: perhaps I should skip putting the connection string as a portal setting, and instead just keep it in web.config. That way, when swapping, the app won't need to restart, and since web.config will be included in the swap, the new production slot will use the updated database.

Edit 2: I think I was mistaken about the app restart when app settings or connection strings differ between slots. It seems I can indeed set a different connection string (pointing to the database copy) for the deployment slot, and then swap without an app restart affecting website visitors.

1
Out of curiosity, did you find a valid solution for this?d.rodriguez
@d.rodriguez Here's how we do it for Episerver websites: tedgustaf.com/blog/2017/zero-downtime-deployment-of-episerverTed Nyberg

1 Answers

0
votes

Could you not make the connection string sticky to the slot?

enter image description here

Full details are here.