JPA Buddy alternative for SpringBoot

428 Views Asked by At

I'm developing a rest API with SpringBoot. I'm using with it Spring Data JPA and Flyway to handle migrations. I'm looking for a way to automate the generation of SQL scripts for my datasource migrations. A bit like what the php symfony framework offers with its ORM doctrine. When I update my JPA entities, I want to be able to automatically generate the SQL corresponding to the changes between my entities in my code and the current state of my database.

Until now, I was using Intellij IDEA's "JPA BUDDY" plugin, which offered exactly this functionality in its premium mode. Recently, however, this functionality is only available in Intellij IDEA ultimate, and the license is too expensive for me.

So far I've tried to look for other alternatives, but since this JPA Buddy unavailability is brand new, I haven't found one yet. Do you have any suggestions?

1

There are 1 best solutions below

0
On

Here's the solution I came up with. Put this in you application.properties file:

spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=update
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=db-migration.sql
spring.jpa.properties.javax.persistence.schema-generation.database.action=none
spring.jpa.hibernate.ddl-auto=none
spring.jpa.generate-ddl=true

And run the program. It will generate an SQL database migration script which then you can use however you want (Flyway, Liquibase...). These properties are set to "none" so the database don't get updated immediately, instead, you just generate a database migration script.

spring.jpa.properties.javax.persistence.schema-generation.database.action=none
spring.jpa.hibernate.ddl-auto=none

Keep in mind that the script generation might not be perfect and exactly what you wanted, so you should check it every time and add manually SQL code if something's missing.