Springboot Migration Automation

Is there a way to generate an SQL file for all changes that happens to my entities each time i start my app such that i can copy/paste this sql file into my production and manually alter my tables after i finish working on a feature in springboot that would change some entities?
57 Replies
JavaBot
JavaBot•7d ago
āŒ› This post has been reserved for your question.
Hey @Saeed Muhaisen! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
ayylmao123xdd
ayylmao123xdd•7d ago
im not sure if thats what you need but you may look into liquibase
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
if you know a better aproach please let me know
dan1st
dan1st•7d ago
you can use automatic DDL upgrading on your local machine (with a DB in Docker) and enable SQL logging then you get the SQL statements in the console
ayylmao123xdd
ayylmao123xdd•7d ago
great sentence :GnuTrolling: nooooo shouldve kept it
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
damn what did i miss this is too exhausting, i am currently considering flyway
dan1st
dan1st•7d ago
I meant if you want to generate the SQL you can then tweak and put in the migration script
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
yeah I am reading more and more and i feel its not good approach I feel there must be a better way to track changes I wonder what happens in real companies how do they handle this
dan1st
dan1st•7d ago
it can be useful as a starting point for writing the changes
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
this is very similar to what i do currently every release i generate new file from local db, and compare with prev generated file and do my own script
dan1st
dan1st•7d ago
typically either SQL first and then the entities or do the entities and then write the SQL manually ig
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
yup, this is most of the things i am seeing online. but its weird that java springboot community hasn't figured out a better way i work currently in python django and we can just create a migration file which would run automatically when we push to production cicd
dan1st
dan1st•7d ago
the thing is you typically want to specify it manually flyway is doing that
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
would you say its good to go with flyway?
dan1st
dan1st•7d ago
but the migration file is SQL yes
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
but wouldn't this mean i will have to give my springboot app the power to update the database directly? i used to think this is bad approach and can cause issues, i always seperated between the two springboot app has read write on tables but database owns everything
dan1st
dan1st•7d ago
I thought you were talking about how to write the SQL content?
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
nono i am generally speaking about the approach i have app on production, i currently do update manually before each release then i do the release in aws
dan1st
dan1st•7d ago
I think you can specify different credentials for flyway
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
like update database then push new release image to docker
dan1st
dan1st•7d ago
but it's still in the same application
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
but is this safe
dan1st
dan1st•7d ago
and yes you could also run flyway in your CI/CD pipeline but this is typically not done
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
yeah idk too many options I might use flyway and manually apply the changes copy pasting them on db
dan1st
dan1st•7d ago
doing it in the pipeline also has issues
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
yeah i wouldn't dare do that many things can go wrong
dan1st
dan1st•7d ago
Like you don't want the migration when the application is still running and if the app does it, it can do so on startup (and rollback if it fails)
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
i read rollbacks are premium on flyway and liquibase
dan1st
dan1st•7d ago
What? not with flyway AFAIK
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
yeah you have to be on premium on flyway to do rollbacks
dan1st
dan1st•7d ago
ah ok you can just create another migration though
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
yup+ ii think i will go with flyway and create the V1__ files, then manually apply them on database whenever a release must happen
dan1st
dan1st•7d ago
well that's adding another step to releases typically you'd want releases to be automated
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
Yeah for sure but i feel this is the only approach that gets applied in production in corprates. i am thinking like: 1. add flyway 2. with each feature creation i create VXfeature.sql file and RXfeature_rollback.sql 3. before release run VX__feature on database 4. push the new release to the server anything goes bad i would use RX_feature_rollback and i think later i can make a cicd for the whole process
dan1st
dan1st•7d ago
flyway does support that both at startup and with scripts I think
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
i want to not give it too much power
dan1st
dan1st•7d ago
but the rollback is a premium thing you can still do it in the CI
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
i want to do it manually in script yeah
dan1st
dan1st•7d ago
if you add manual steps to your release process, that's your decision
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
Dealing with databases is just next level stress šŸ˜„ manual might save me from catastrophes
dan1st
dan1st•7d ago
backups actually save you from catsstrophes
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
Yeah i am trying to save some $$
dan1st
dan1st•7d ago
the biggest risk is you making a mistake innthe migration script and you messung up the manual step - e.g. forgetting to run it and if something goes wrong you can still do a rollback even with the free version
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
So in your opinion i should do flyway with direct access to update
dan1st
dan1st•7d ago
probably- either that or in a CI if this is applicable for your application
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
i think ill go flyway with direct access i am going to test it locally and see if its not scary ill do ti
dan1st
dan1st•7d ago
the main risk there is your migration script doing something stupid
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
yup, and idk if flyway would allow me to run the script before runnign springboot but i think that is available
dan1st
dan1st•7d ago
and is there really much of a difference between your application deleting all data and your application dropping tables? you should be able to use flyway in a standalone way
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
true
dan1st
dan1st•7d ago
I think there's even a Maven plugin but idk what exactly that does
ayylmao123xdd
ayylmao123xdd•7d ago
ig you could do flyway and liquibase if they support each other for even better experience 😱
dan1st
dan1st•7d ago
where's the better experience in using both?
Saeed Muhaisen
Saeed MuhaisenOP•7d ago
It will be headache managing both of them
dan1st
dan1st•7d ago
managine oneself is already sufficient headache
ayylmao123xdd
ayylmao123xdd•7d ago
to better feel the pain of managing 2 of these at once l0l
JavaBot
JavaBot•7d ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?