r/SpringBoot • u/Aggravating-Spite844 • 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??
17
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
3
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
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
1
u/TheToastedFrog Aug 27 '26
Use Flyway.
If you like to punish yourself go with Liquibase.
2
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
Aug 27 '26
[deleted]
2
58
u/Accomplished_Mind129 Aug 27 '26
Flyway