Hooks into Play evolutions?

2019-06-26 06:22发布

问题:

Is there a way to hook into Play evolutions framework such that when it succeeds migrating from n.sql to n+1.sql to n+2.sql ..., it calls some post-success hook in the Play app (something like postSchemaMigration(n: Int)? Can I manually check and apply evolutions one by one in the global object somewhere before the server bootstraps?

回答1:

As it stands, Play has no in-built mechanism to allow you to control the evolution process. Either it succeeds completely, or it fails. If your application runs, then all evolutions have been applied

Depending on your use case, you have a few options. The most flexible is simply to not use Play's evolution framework, and apply your database evolutions with custom code in the global object, using plain-ol' JDBC. On roughly the same lines, you could implement a custom Play plugin that applies your evolutions.

Or you could modify the existing evolution framework. Play is open source, after all, and if your code solves a common problem, it may even make sense to submit it for inclusion in the standard Play distribution.