<p>I have a microservice which connects directly to PostgreSQL. 
PostgreSQL is already deployed and running on Kubernetes cluster. 
<br>I'm planning to deploy microservice and curious, is there any way to create DB schema during microservice deployment? 
<br>There can be more microservices and they can use different schemas, but during PostgreSQL deployment how schemas should look like it's not known yet.</p>

Remigijus Kutkaitis
<p>During deployment of the service which requires a DB, you need to ensure that the DB is in a state where the service can operate on. </p>

<p>You can use <a href="https://flywaydb.org/" rel="nofollow noreferrer">Flyway</a> for this. It supports migrating a database based on sql scripts and also is version aware, so if you for example execute flyway migrations a second time, it wont do the changes again. </p>

<p>This can be run as part of your deployment procedure, or within an init container or even can <a href="https://blog.8bitzen.com/using-flyway-java-migrations-with-spring-boot/" rel="nofollow noreferrer">be injected into your code directly</a>, so everytime your app starts up it will ensure the db state is given. </p>
