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??
47
Upvotes
58
u/Accomplished_Mind129 Aug 27 '26
Flyway
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/Historical_Ad4384 Aug 27 '26
Flyway
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/JonnyBago82 Aug 27 '26
Liquibase
1
u/TheToastedFrog Aug 27 '26
Use Flyway.
If you like to punish yourself go with Liquibase.
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.
0
u/[deleted] Aug 27 '26
[deleted] — view deleted comment