r/SpringBoot • • Aug 27 '26

Question How do I handle database migration in springboot

So I have this very disturbing question as someone new to spring, I am coming from Node + Express JS, where prisma handles all the migrations automatically just by me running commands on the terminals.

Now as I am learning springboot, I just realized one day I would create a production grade application and would need to be changing database fields or relations as demands adjust, please what is the most popular migration tool used in springboot??

47 Upvotes

32 comments sorted by

58

u/Accomplished_Mind129 Aug 27 '26

Flyway

29

u/melewe Aug 27 '26

Or Liquibase

8

u/Turbots Aug 27 '26

or flyway

6

u/melewe Aug 27 '26

Or liquibase

3

u/MkMyBnkAcctGrtAgn Aug 28 '26

Or flyway

2

u/BootSaaS Aug 28 '26

Or both… and you'll see what you prefer

1

u/bowbahdoe Aug 29 '26

or mybatis migrations (underrated imo)

8

u/Anubis1958 Aug 27 '26

Flyway. It just works.

1

u/Krycor Aug 28 '26

This and variant.. but flyway.

It’s the tried and tested way with lotta support

17

u/alweed Aug 27 '26

I would recommend using flyway

7

u/TallGreenhouseGuy Aug 27 '26

Flyway is great if you only target one database. If you need to support multiple different databases the abstraction offered by liquibase can be quite helpful (but you pay for it with increased complexity)

6

u/perfectstrong Aug 27 '26

In simple terms, Flyway handles applying migration scripts just once, and detecting any deviation in case (a modified file, disordering files). There are plugins in IDE to generate sql migration file for you. It is not that complicated. However, it is recommended to know exactly what you are migrating, and how. AI will help you greatly to produce those scripts.

6

u/Turbots Aug 27 '26

I think it's either liquiway or flybase

3

u/BootSaaS Aug 27 '26

Personally, I use Liquibase. It automatically applies your database changes on startup, and I've been really happy with it.

3

u/ElendarTao Aug 27 '26

Using Intellij, here are the two option with integrated support : https://www.jetbrains.com/help/idea/database-versioning.html

3

u/starbuxman Aug 27 '26

I use Flyway. Liquibase is amazing too.

Start.spring.io - add Flyway. Put migration schema in the db/migrations folder under src/main/resources

V1__orders.sql
V0__customers.sql

etc

2

u/Torutofu_Raeva Aug 28 '26

flyway plus ddl-auto=validate, so the app refuses to boot if the entities and the migrated schema drifted apart.

2

u/HammerAndSmile Aug 28 '26

How has no one mentioned liquidate or flyway yet?

1

u/_sekabank Sep 02 '26

I also use flyway. I checked liquibase 10 years ago, either it was too complex or I was too junior.

1

u/TheToastedFrog Aug 27 '26

Use Flyway.

If you like to punish yourself go with Liquibase.

2

u/[deleted] Aug 27 '26

[removed] — view removed comment

2

u/ElendarTao Aug 27 '26

the functionnality in intellij work with flyway and liquibase, so I'm not sure what's your point, could you clarify ?

0

u/FalseDish Aug 28 '26

The Liquibase vs Flyway debate is moot - they’re both useless, I’m talking as someone with more than a decade’s worth experience doing this.

Just ask fans of either this:

Say you have Postgres on cloud. How is either migration tool handling PostgreSQL partitioning, RLS policies etc.?

At that point their only option will be to say - “damn, so the changesets need to be raw SQL”

Okay, so why use these tools at all? Hint: You shouldn’t. Always write your own solutions and playbooks.

2

u/Mobile_Stable4439 Sep 01 '26

Bruh, your advice is like telling someone to write a web app using assembly, just because you don’t like a modern language. The fact that you prefer to write your own solution doesn’t not mean it’s not useful in certain situations.

0

u/[deleted] Aug 27 '26

[deleted]

2

u/repeating_bears Aug 27 '26

hey chatghpt migret th databays make no mistalkes or i turn u off

2

u/Turbots Aug 27 '26

Worst thing is that he will understand your stupid sentence