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•8mo 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•8mo ago
im not sure if thats what you need but you may look into liquibase
Ed
EdOP•8mo ago
if you know a better aproach please let me know
dan1st
dan1st•8mo 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•8mo ago
great sentence :GnuTrolling: nooooo shouldve kept it
Ed
EdOP•8mo ago
damn what did i miss this is too exhausting, i am currently considering flyway
dan1st
dan1st•8mo ago
I meant if you want to generate the SQL you can then tweak and put in the migration script
Ed
EdOP•8mo 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•8mo ago
it can be useful as a starting point for writing the changes
Ed
EdOP•8mo 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•8mo ago
typically either SQL first and then the entities or do the entities and then write the SQL manually ig
Ed
EdOP•8mo 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•8mo ago
the thing is you typically want to specify it manually flyway is doing that
Ed
EdOP•8mo ago
would you say its good to go with flyway?
dan1st
dan1st•8mo ago
but the migration file is SQL yes
Ed
EdOP•8mo 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•8mo ago
I thought you were talking about how to write the SQL content?
Ed
EdOP•8mo 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•8mo ago
I think you can specify different credentials for flyway
Ed
EdOP•8mo ago
like update database then push new release image to docker
dan1st
dan1st•8mo ago
but it's still in the same application
Ed
EdOP•8mo ago
but is this safe
dan1st
dan1st•8mo ago
and yes you could also run flyway in your CI/CD pipeline but this is typically not done
Ed
EdOP•8mo ago
yeah idk too many options I might use flyway and manually apply the changes copy pasting them on db
dan1st
dan1st•8mo ago
doing it in the pipeline also has issues
Ed
EdOP•8mo ago
yeah i wouldn't dare do that many things can go wrong
dan1st
dan1st•8mo 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)
Ed
EdOP•8mo ago
i read rollbacks are premium on flyway and liquibase
dan1st
dan1st•8mo ago
What? not with flyway AFAIK
Ed
EdOP•8mo ago
yeah you have to be on premium on flyway to do rollbacks
dan1st
dan1st•8mo ago
ah ok you can just create another migration though
Ed
EdOP•8mo 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•8mo ago
well that's adding another step to releases typically you'd want releases to be automated
Ed
EdOP•8mo 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•8mo ago
flyway does support that both at startup and with scripts I think
Ed
EdOP•8mo ago
i want to not give it too much power
dan1st
dan1st•8mo ago
but the rollback is a premium thing you can still do it in the CI
Ed
EdOP•8mo ago
i want to do it manually in script yeah
dan1st
dan1st•8mo ago
if you add manual steps to your release process, that's your decision
Ed
EdOP•8mo ago
Dealing with databases is just next level stress šŸ˜„ manual might save me from catastrophes
dan1st
dan1st•8mo ago
backups actually save you from catsstrophes
Ed
EdOP•8mo ago
Yeah i am trying to save some $$
dan1st
dan1st•8mo 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
Ed
EdOP•8mo ago
So in your opinion i should do flyway with direct access to update
dan1st
dan1st•8mo ago
probably- either that or in a CI if this is applicable for your application
Ed
EdOP•8mo 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•8mo ago
the main risk there is your migration script doing something stupid
Ed
EdOP•8mo ago
yup, and idk if flyway would allow me to run the script before runnign springboot but i think that is available
dan1st
dan1st•8mo 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
Ed
EdOP•8mo ago
true
dan1st
dan1st•8mo ago
I think there's even a Maven plugin but idk what exactly that does
ayylmao123xdd
ayylmao123xdd•8mo ago
ig you could do flyway and liquibase if they support each other for even better experience 😱
dan1st
dan1st•8mo ago
where's the better experience in using both?
Ed
EdOP•8mo ago
It will be headache managing both of them
dan1st
dan1st•8mo ago
managine oneself is already sufficient headache
ayylmao123xdd
ayylmao123xdd•8mo ago
to better feel the pain of managing 2 of these at once l0l
JavaBot
JavaBot•8mo 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?