Managing evolutions in production environment

﹥>﹥吖頭↗ 提交于 2019-12-02 20:49:39
Chris

Edit: Updated for Play 2.5


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.

Recommended settings

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

play.evolutions.db.default.autoApply=true

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

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.

Recovering after evolutions failure

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.

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.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!