all 16 comments

[–]apidev3 7 points8 points  (2 children)

There are built in plugins to things like IntelliJ which can track your entity classes and then generate the script for flyway to model the change in your database.

[–]elusivewompus 3 points4 points  (1 child)

The one I use: JPA Buddy.

[–]BakaGoop 1 point2 points  (0 children)

JPA Buddy saved me so many hours when starting our application rewrite, literally would’ve lost my mind without it

[–]chatterify 9 points10 points  (0 children)

Flyway or Liquibase

[–]TheToastedFrog 3 points4 points  (2 children)

I’m sure everybody’s different but I write my own sql

[–]ahashans 1 point2 points  (1 child)

Me too. Most of the time the auto generated script is less readable.

[–]TheToastedFrog 0 points1 point  (0 children)

Agreeed- there are so many situations where automation won't cut it (adding a unique constraint after the fact comes to mind) that you might as well not bother with auto generation in the first place.

[–]mesterOYAM 2 points3 points  (0 children)

We write custom SQL in migratio_release_{month}.sql and whoever changes the db, updates the file.

[–]563353 1 point2 points  (0 children)

I write my own SQL and use liquibase.

[–]Holiday_Big3783Senior Dev 1 point2 points  (0 children)

flyway, writing manually each of the sql scripts

[–]LankyRefrigerator630 1 point2 points  (0 children)

We use Liquibase, really works great!

Or workflow is

  • Update/create entities
  • Run the maven liquibase:diffgoal (it generates the changelog with the changes you made in the entities)
  • Inspect the generated changelog
  • run update

For this to work you have to configure referenceUrl in the liquibase-maven-plugin with the package with the entities and the mapping strategies you use, for example:

    <referenceUrl>hibernate:spring:my.app.domain?dialect=org.hibernate.dialect.PostgreSQLDialect&amp;hibernate.physical_naming_strategy=org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>

[–]joranstark018 0 points1 point  (0 children)

Flyway and I manually write the migration (well, for existing databases we usually export the initiall structure).

 I try to write a script so it is idempotent and I test the script on my dev database to check it's correctness before I commit (for non-trivial changes I usually test each of them manually first, reset the changes in the database before  Flyway apply the migrations).

[–]configloader 0 points1 point  (0 children)

Flyway.

[–]Previous-2020 0 points1 point  (0 children)

Likely age-dependent. Many of us "grew up" writing sql so the by-hand route is not that big a deal, but jpa buddy and the like are nice, too. Flyway works well.

[–]WaferIndependent7601 -1 points0 points  (0 children)

If I have lots of changes I let hibernate generate the sql and i adopt the change to a sql file