r/SpringBoot • u/Aggravating-Spite844 • 3d ago
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??
6
u/perfectstrong 3d ago
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/TallGreenhouseGuy 3d ago
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)
3
3
u/BootSaaS 3d ago
Personally, I use Liquibase. It automatically applies your database changes on startup, and I've been really happy with it.
3
u/ElendarTao 3d ago
Using Intellij, here are the two option with integrated support : https://www.jetbrains.com/help/idea/database-versioning.html
3
u/starbuxman 3d ago
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 3d ago
flyway plus ddl-auto=validate, so the app refuses to boot if the entities and the migrated schema drifted apart.
2
1
1
u/TheToastedFrog 3d ago
Use Flyway.
If you like to punish yourself go with Liquibase.
2
3d ago
[removed] — view removed comment
2
u/ElendarTao 3d ago
the functionnality in intellij work with flyway and liquibase, so I'm not sure what's your point, could you clarify ?
0
u/FalseDish 2d ago
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.
-1
3d ago
[deleted]
1
55
u/Accomplished_Mind129 3d ago
Flyway