具有数据库迁移功能的Azure Web App部署插槽 [英] Azure Web App deployment slots with database migration

查看:80
本文介绍了具有数据库迁移功能的Azure Web App部署插槽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在运行具有多个部署位置(例如开发,登台,生产)的webApp。每个插槽都连接到数据库(db_dev,db_staging,db_production)。我想部署到暂存插槽,然后进行生产切换。

I'm currently running a webApp with several deployment slots (e.g. dev, staging, production). Every Slot is connected to a database (db_dev, db_staging, db_production). I want to deploy to the staging slot and then switch with production. How do database migrations fit in here?

我的意思是,如果我部署了带有数据库迁移的新版本来升级db_staging,那么我会这样做。如果切换插槽会怎样?迁移是否适用于db_production?停机时间如何?

I mean, if i deploy a new build with db migrations to staging the db_staging gets updated. What happens if I switch the slots? Do the migrations get applied to db_production? What about downtimes?

据我了解,只有URL被切换,所以切换之后,暂存槽中的应用程序将指向db_production?

From my understanding only the URLs are switched, so after the switch the app in the staging slot would point to the db_production? That does not make sense.

我可以部署到暂存插槽并指向db_production(带有迁移),但是随后数据库将被更新,并且可能会破坏应用程序

I could deploy to the staging slot and point to db_production (with migrations), but then the db would be updated and could possibly break the app in the live slot.

推荐答案

不要在源代码中对连接字符串进行硬编码,而是将它们放在连接字符串部分的下面。您的应用程序服务设置并将其作为环境变量进行访问。它不仅更安全,因为它可以让您在任何环境下只有一个代码,并且通过将设置检查为插槽设置(无论是否交换),对于该插槽,配置均保持不变。

Instead of hard coding the connecting string in your source code, put them under the connecting strings section of your app service settings and access it as an environment variable. It's not only safer as it will allow you to have just one code for any environment and by checking the setting as a "slot setting" no matter if you swap or not, for that slot, the configuration remains fixed.

此处提供更多信息:

https: //azure.microsoft.com/zh-CN/documentation/articles/web-sites-configure/

更新

在数据库更新的情况下,即,需要运行必要的脚本以更新新应用程序版本的数据库模式,您可以使用applicationInitialization您的web.config部分。通常用于预热应用程序,但也应适合您的情况。

In the case of a database update, i.e, necessary scripts that need to be run in order to update the database schema for the new app version, you can use the applicationInitialization section of your web.config. Usually used to warm-up the app, but should work for your case as well.

<system.webServer>  
  <applicationInitialization >  
    <add initializationPage="/init-script.php" hostName="xxxxxx.azurewebsites.net"/>  
  </applicationInitialization>  
<system.webServer> 

AppInit模块将等待此代码完成,然后再完成交换过程,这基本上使生产流量能够该应用程序。基本逻辑将检查数据库是否正在运行预期版本,如果不是,则将依次执行其他一些逻辑。

The AppInit module will wait until this code completes before finishing the swap process which is basically allowing production traffic to the app. Basic logic would be checking if the database is running the expected version and if not some other logic would be executed in sequence.

这篇关于具有数据库迁移功能的Azure Web App部署插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆