How do I perform database diff generation with Quarkus and Hibernate?

190 Views Asked by At

Currently, I'm using PostgreSQL for my database and Quarkus with Hibernate ORM. For a while, I just used Hibernate's default HBM2DDL. Eventually, I discovered that it couldn't update every change I was making to my entities. Now I'd like to use a proper database migration tool and run something that will generate diff SQL files that I can edit before putting into production.

My question is: how do I set up Quarkus and Hibernate ORM entities so that I can generate SQL diff files for database migrations?

Here's what I've tried so far:

When using Quarkus, the main two supported database migration tools appear to be Flyway and Liquibase. I tried integrating each of these separately and ran into a number of issues:

  • Integrating Flyway worked nicely, but trying to hand write SQL migration files by studying my PanacheEntities and copying out Hibernate-generated changes became super tedious.

  • As a temporary workaround, I used Quarkus's Dev UI to generate "initial migration" SQL files for several different versions of my application, and then I went through and edited each file so that it would migrate correctly. This worked, but still required a lot of time and trial and error.

  • I discovered that using JPA Buddy is a common answer to this question. Sadly, generating diff migrations with JPA Buddy has since become a paid feature, so I would like to look elsewhere.

  • I restarted to a point before Flyway and integrated Liquibase, which was even faster to set up by reusing the SQL files I made for Flyway. I got the migration working, but still needed a solution to generate SQL diffs. Despite Liquibase having support for generating a diff with Maven, Quarkus's Liquibase page does not seem to have any support for it, or make any mention of how to improve writing migrations for future versions.

  • I tried adding liquibase-hibernate as a dependency to the project, which also involved adding several other things to my pom.xml file, making a liquibase.properties file (even though I already have an application.properties file), and attempting to write an implementation of the CustomMetadataFactory class. It seems promising, but Quarkus changes things about Hibernate which prevents me from being able to exactly follow a tutorial for using Liquibase and Hibernate together.

I find myself pretty stuck at this point. Generating a diff between a local development database and my current JPA entity changes seems to be possible with simpler Hibernate projects and with Spring Boot. What can I do?

0

There are 0 best solutions below