DEV Community


Discussion on: Database (Schema) migration to Kubernetes - initContainers vs k8s jobs -

pjotre86 profile image
pjotre86 • Edited

Regarding the setup script:
The k8s-job you created is needed to run before you can start the application. So it's effectively a setup script. If you want to run your app somewhere else, let's say directly on your machine or with docker-compose you need to run similar scripts there as well in order to make it work. That also means that your application is not self-sufficient. If you manage to do the db-migrations within the startup of your application it becomes much more flexibel, easier to use, less error-prone (because you don't need to maintain scripts for different runtimes), easier to test (both manual and automated end-to-end tests are easier to setup when there's not this extra step of running the migration-script every time). Just point the app to a db-server and let it do the rest.

Regarding libraries:
As already mentioned, I'm not an expert on PHP/Lavarel at all. But I saw in your profile that you have a Java-background. In Java the de-facto standard library which does exactly this kind of stuff would be liquibase. Maybe someone else here knows of an equivalent for this in the PHP-world, or maybe you find something if you research a bit. I would be highly surprised if there's nothing like that, regarding the maturity of PHP...

Hope I could clarify my points a bit...

Thread Thread
ahmeddrawy profile image
Ahmed Hanafy Author

You did clarify, thank you
Regarding the db migration we limited it to the production db only
Our dev env has it’s migration managed in other way -not sure how but i think it’s handled using docker-compose -
Will check the Java library thank you very much
This is my first article and I’m still junior SWE learning DevOps so I hope my article -in which i put alot of effort - helped you a bit

Thread Thread
pjotre86 profile image

Thanks for the article. It made me think, that's always good. I'm not saying your approach is bad. In my mind I just applied it to the projects I'm working on and then those concerns came to my mind. But you're working on a different thing on a different stack so it might be no problem for you after all. Anyway, I guess most companies would be happy for a junior dev who comes up with such a solution!