管理生产环境的演变 [英] Managing evolutions in production environment

查看:22
本文介绍了管理生产环境的演变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 play 2.1.1 将新应用程序部署到生产环境中,但遇到了一些实际问题,非常有限的文档也没有多大帮助...

We are in the process of deploying a new application using play 2.1.1 to production and are having some real issues with it and the very limited documentation didn't help much...

所以是时候更新到新版本了,我们运行了通常的停止/升级/启动脚本,但它们失败了.出于某种原因,游戏拒绝应用进化.启动时一直提示

So it was time to update to a new version, we ran our usual stop/upgrade/start scripts but they failed. For some reason, play was refusing to apply the evolutions. When starting it kept saying

糟糕,无法启动服务器.@6elnj89fh:数据库默认"需要进化!

Oops, cannot start the server. @6elnj89fh: Database 'default' needs evolution!

即使我们尝试通过命令行和 application_prod.conf 文件设置 applyEvolutions.default=true 也是如此.它还抱怨

This was even though we tried setting applyEvolutions.default=true both through command line and in the application_prod.conf file. It also complained that

警告!此脚本包含可能具有破坏性的 DOWNS 演变

WARNING! This script contains DOWNS evolutions that are likely destructives

这对我来说没有多大意义,因为我们正在升级版本,所以无论如何都不应该应用降级.但似乎这可能是它拒绝应用进化的原因.

which doesn't make much sense to me since we are going up in version so the downs should not be applied anyway. But it seems this might have been the reason it was refusing to apply the evolutions.

此时我并不担心,因为我认为有一些手动方法可以应用进化.经过大量搜索后,它看起来好像......在第 1 次播放但没有在第 2 次播放中支持.在开发模式下,您只需按浏览器中的按钮即可应用进化,但在生产模式下我找不到任何方法手动应用进化.这是真的还是我错过了?我真的认为这是一个重要的功能!(事后看来,我本可以手动应用脚本并禁用进化插件,但那样我就会失去有用的进化跟踪..)

At this point I wasn't so worried as I assumed that there is some manual way to apply evolutions. After extensive searching it looks as though... There was support for this in play 1 but not in play 2. In dev mode you can just press a button in the browser to apply the evolutions but in prod mode I could find NO WAY OF MANUALLY APPLYING EVOLUTIONS. Is this true or did I miss it? I really think this is an important feature! (In hind sight I could have applied the scripts manually and disabled the evolutions plugin but then I would have lost the evolutions tracking which is useful..)

我也想知道您将如何支持"您的数据库,因为我相信我们会在某个时候需要这样做.如果有一种手动方式来做到这一点,它可能会有一个可选的版本参数来降级数据库.例如.如果您使用的是第 5 版并且需要返回到第 4 版,则运行 play apply-evolutions 4 它将应用第 5 版的降级并相应地更新进化数据库.我可以手动应用downs,但问题是evolutions db将再次处于无效状态......

I also wonder how you would go about "backing" your database as I am sure we will get to a point when we need to do that at some point. If there was a manual way to do this it would probably have an optional version argument to downgrade the database. E.g. if you are at version 5 and need to go back to 4 you run play apply-evolutions 4 which would then apply the downs from version 5 and update the evolutions db accordingly. I could apply the downs manually but then again the problem is the evolutions db will once again be in an invalid state...

越来越绝望,我尝试了所有我能找到的设置来重新启动服务器并添加了 -DapplyDownEvolutions.default=true 选项.我认为此设置仅在选择降级数据库时才会应用降级(尽管似乎没有这样的选项)但实际上它所做的是应用升序然后立即应用降级(我后来在故障排除中发现了这一点)服务器现在终于启动了 - 没有任何消息 - 但在访问该站点时给出了一个神秘的错误消息).这是这个设置应该做的吗?如果是,我无法理解为什么设置甚至存在.我想不出在迁移到更新的数据库版本时您希望应用 ups 然后立即 downs 的任何场景.有人可以解释一下这个设置吗?

Getting more desperate I tried all the settings I could find to get the server up again and added the -DapplyDownEvolutions.default=true option. I assumed this setting would apply downs only when choosing to downgrade the DB (although there seems to be no such option) but what it in fact did was to apply the ups and then instantly apply the downs (I found this out later in troubleshooting as the server now finally started - without any message whatsoever - but gave a cryptic error message when visiting the site). Is that what this setting is supposed to do? If it is I can't understand why the setting even exists. I can't think of any scenario where you would want to apply ups and then instantly downs while migrating to a newer database version. Can someone shed some light on this setting?

此时我终于可以通过手动重新运行适当的UPs"来再次运行应用程序.

At this point I could finally get the app running once again by manually re-running the appropriate "UPs".

在这一点上,我们正在基本上重写脚本来处理我们自己的进化,以便更好地控制运行的内容并能够返回......如果能够使用播放功能所以我希望有人能对此有所了解.如果没有,也许这个咆哮可以帮助处于类似情况的人......

At this point we are working on basically re-writing scripts for evolutions handling on our own to have some better control of what is run and to enable going back.. It would be much better to be able to use play functionality for this so I am hoping someone can shed some light on this. If not, maybe this rant can help someone in a similar situation...

推荐答案

针对 Play 2.5 更新

大约 3 年多以来,我们一直在使用 Play 的演进进行制作,并且从未遇到过严重问题.

We're using Play's evolutions for production since about 3+ years and never had serious issues with it.

我建议您拥有一个临时环境,您可以先在该环境中针对测试数据库运行演进.测试数据库应与生产数据库具有完全相同的版本.你会在你的进化中犯错误,这是一种在它们进入生产服务器之前找到它们的方法.

I recommend having a staging environment, where you run your evolutions against a test database first. The test database should have the exact same version as the production database. You WILL make mistakes in your evolutions, and this is a way to find them before they go to the production server.

对于我们的生产系统,我们启用了以下设置:

For our production system, we have the following setting enabled:

play.evolutions.db.default.autoApply=true

设置 autoApply 确保自动应用演变,无需用户交互.显然,这就是我们升级生产数据库时想要的.

The setting autoApply makes sure that evolutions are applied automatically, without user interaction. Obviously, this is what we want when upgrading our production database.

对于我们的暂存/测试系统,我们启用了这两个设置:

For our staging/testing system, we have both settings enabled:

play.evolutions.db.default.autoApply=true
play.evolutions.db.default.autoApplyDowns=true

第二个设置 applyDownEvolutions 确保自动应用 DOWNS 进化.我们不希望在我们的生产系统上出现这种情况,因为它可能会导致数据丢失(因为 DOWNS 演进通常包含诸如 DROP TABLE 等内容).

The second setting applyDownEvolutions makes sure that also DOWNS evolutions are applied automatically. We do NOT want this on our production system, because it may lead to data loss (since DOWNS evolutions often contain things like DROP TABLE etc).

然而,在测试系统上,如果您正在测试应用程序的不同分支或版本,您可能需要在不同的数据库版本之间切换.在这种情况下,您可能希望在测试新分支时自动关闭和升级数据库.

On the testing system however, if you're testing different branches or versions of your application, you may want to switch between different database versions. In this case, you may want to automatically down and upgrade your database as new branches are tested.

请记住,如果一次演变因 SQL 错误(在生产或测试系统上)而失败,您必须手动将数据库恢复到正常状态.您可以通过查看 play_evolutions 表来做到这一点.Play 会跟踪应用的演变及其错误.最后一个条目显示了最后应用的进化以及遇到的错误.

Keep in mind that if one evolution fails due to an SQL error (on production or testing system), you'll have to restore the database to a sane state manually. You can do this by looking at the play_evolutions table. There Play keeps track of applied evolutions and their errors. The last entry shows the last applied evolution and also the error that was encountered.

从错误消息中,您通常可以追踪错误的 SQL 并修复您的进化脚本.然后您可以将数据库恢复到之前的进化版本,并从 play_evolutions 表中删除失败的进化条目.Play 然后认为新的进化还没有被应用,并会再次运行它.

From the error message, you can usually track down the bad SQL and fix your evolutions script. You can then revert the database to the previous evolution version, and remove the failed evolution entry from the play_evolutions table. Play then thinks that the new evolution hasn't been applied yet, and will run it again.

希望这会有所帮助.

这篇关于管理生产环境的演变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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