[英]Azure Web App deployment slots with database migration
I'm currently running a webApp with several deployment slots (eg dev, staging, production). 我目前正在运行带有多个部署插槽的webApp(例如dev,staging,production)。 Every Slot is connected to a database (db_dev, db_staging, db_production). 每个Slot都连接到一个数据库(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? 数据库迁移如何适应这里?
I mean, if i deploy a new build with db migrations to staging the db_staging gets updated. 我的意思是,如果我将具有db迁移的新构建部署到分段,则db_staging会更新。 What happens if I switch the slots? 如果我切换插槽怎么办? Do the migrations get applied to db_production? 迁移是否应用于db_production? What about downtimes? 停机时间怎么样?
From my understanding only the URLs are switched, so after the switch the app in the staging slot would point to the db_production? 根据我的理解,只有URL被切换,所以在切换后,临时插槽中的应用程序将指向db_production? That does not make sense. 那没有意义。
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. 我可以部署到临时插槽并指向db_production(使用迁移),但随后数据库将被更新,并且可能会破坏实时插槽中的应用程序。
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. 它不仅更安全,因为它允许您只为任何环境提供一个代码,并通过将设置检查为“插槽设置”,无论您是否交换,对于该插槽,配置保持固定。
More info here: 更多信息:
https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/ https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/
Update : 更新 :
In the case of a database update, ie, 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. 对于数据库更新(即,为了更新新应用程序版本的数据库架构而需要运行的必需脚本),可以使用web.config的applicationInitialization部分。 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>
The AppInit module will wait until this code completes before finishing the swap process which is basically allowing production traffic to the app. AppInit模块将等到此代码完成后再完成交换过程,这基本上允许应用程序的生产流量。 Basic logic would be checking if the database is running the expected version and if not some other logic would be executed in sequence. 基本逻辑将检查数据库是否正在运行预期版本,如果不是,则将按顺序执行某些其他逻辑。
I have been pondering this too, and as far as I can see the only sensible process is as follows: 我一直在思考这个问题,据我所知,唯一明智的过程如下:
If you can keep your db updates non-breaking, then rollback can be simple as swapping the slots back. 如果您可以保持数据库更新不中断,那么回滚可以很简单,就像交换插槽一样。 If not, you are back in the familiar pain of rollback scripts or restoring snapshots. 如果没有,您将回到熟悉的回滚脚本或恢复快照的痛苦中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.