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

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

问题描述

我们正在将使用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中没有提供支持.在开发人员模式下,您只需按浏览器中的按钮即可应用演变,但在生产模式下,我找不到办法手动应用演变.这是真的还是我想念它?我真的认为这是一个重要的功能! (事后看来,我本可以手动应用脚本并禁用Evolution插件,但随后我将失去对Evolution的跟踪,这很有用.)

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..)

我还想知道您将如何备份"您的数据库,因为我确信在某个时候我们将达到一个关键点.如果有手动方法可以执行此操作,则可能会有一个可选的version参数来降级数据库.例如.如果您使用的是版本5,并且需要返回到版本4,请运行play apply-evolutions 4,这将应用版本5的版本,并相应地更新Evolution数据库.我可以手动应用下降,但是问题再次出在,Evolutions数据库将再次处于无效状态...

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选项.我认为此设置仅在选择降级数据库时才应用downs(尽管似乎没有这种选择),但实际上所做的是先应用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?

在这一点上,我终于可以通过手动重新运行适当的"UP"来再次使应用程序运行.

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更新

Updated for 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并修复您的Evolution脚本.然后,您可以将数据库还原到以前的演化版本,并从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天全站免登陆