My current Spring 3.0 project is integrating with Flyway.
Thanks to the google site so there are document I can counting on. But unfortunately there is not much talking about integration with JPA.
So the questions is:
-
How to integrate Flyway with
persistence.xml? And how does it work? Each time JPA provider willauto generateschema update so how we run a script before or after then? -
I guess the query by flyway so far does not support HQL and such so is there any sample code then I can go through to know how to integrate the migration event? Design an interceptor or a new aspect?What to do on a domain level?
Any hint is appreciated. Thanks in advance.
Flyway has no support for JPA
and Spring. It basically runs your SQL (not HQL) scripts in order and keeps track of them. And does it well. It remains agnostic to how you use your database and how you produce your upgrade scripts.However, there’s hope. Your persistence provider will most likely support updating existing schema (I know hibernate and eclipselink can), running ALTER and CREATE statements on startup. The migration SQL scripts aren’t perfect and it won’t always work, but it’s a good start. Log these scripts, collect into SQL file, clean-up and use as
V_*.sqlfile supplied to Flyway.UPDATE: although there is no direct support for spring framework, you can easily integrate it with existing Spring application. This approach is proven to work on production and plays nicely:
Bonus: it works great with Java configuration (with Scala) as well: