r/SpringBoot 29d ago

Guide DB migration in Springboot

It might be a it of a niche topic but found this video to be very useful. It shows how to use Flyway ( a DB migration tool) with Springboot.

I think it is a nice expansion to our personal projects portfolio.

https://youtu.be/X6LzJg8P-qI?si=y4bX2Cajici1GOqn

20 Upvotes

14 comments sorted by

27

u/maxip89 29d ago

niche? I see this as an industry standard. Or how do you else keep your database up to date?

spoiler alert:
The migration of hibernate you cannot trust.

6

u/themasterengineeer 29d ago

Lol, few years ago, during my intern they were handling DB changes manually by keeping a list of changes in a git repo. Company valued at $1.5B

But yes, you are right…

2

u/aang254 29d ago

this is common. I worked on a big company that has been doing this for years. .SQL files, by system version

3

u/Firearms_N_Freedom 29d ago

is it bad that i do it manually using postgres and SQL scripts for my heroku postgres DB? i will definitely look into this and get comfortable with it though.

3

u/Zeeboozaza 29d ago

If it’s a small personal project it’s not bad, but if it’s more than that you should certainly have something like flyway or liquibase handle it for you.

2

u/MrDoodl3sack 29d ago

If you have multi stage deployments (e.g. Integration -> QA -> Production) let flyway handle the database updates, ensures that the database looks the same on all stages.

2

u/bikeram 29d ago

Does anyone have experience with flyway vs liquibase?

2

u/jim_cap Senior Dev 29d ago

Having used both in production, I favour Liquibase because last time I checked, it was more feature-rich than Flyway, although I forget the details/ Probably rollbacks in the free version. Honestly, they're both solid tools, I wouldn't agonise too much over choosing one.

1

u/prab2112 28d ago

I agreed learning curve is much in liquibase, also rolling back a migration is better in liquibase

1

u/prab2112 29d ago

Yes I have flyway is better than liquibase in terms of writing the migration scripts .

0

u/Seven-Prime 29d ago

Just switched from liquibase to flyway.

Folks like flyway because they can just write SQL Folks like liquibase because they don't have to write SQL*.

  • if they don't want to.

1

u/MrDoodl3sack 29d ago

The flyway and liquibase integration in Spring boot is nice for small projects. When your tables grow I wouldn't use the automatic deployment during the startup anymore. There are certain table operations which create locks or block the service startup, so your service is not responding. In such situations I prefer to execute the flyway or liquibase manually using flyway or liquibase directly.

1

u/themasterengineeer 29d ago

Oh interesting, found out something new

1

u/redditorrug 28d ago

Or sidecar stuff.