I am using Spring and Hibernate and I want to create a database before hibernate kicks in otherwise I am getting a Caused by: org.postgresql.util.PSQLException: FATAL: database "db" does not exist.
I have this in my properties file:
spring.datasource.url=jdbc:postgresql://postgres:5432/db
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
server.port=3001
db does not exist in the postgres database so it throws the exception.
Some people say I can use Flyway:
Create PostgreSQL database on the fly using Hibernate even if the DB doesn't exist
Others say it is not possible:
How to create a database with flyway?
How can I accomplish the creation of the db with flyway?
Or if it is used just for the migrations after creation how can I create the initialization bean (can you show me some code) that runs before as stated in the accepted answer here:
Create PostgreSQL database on the fly using Hibernate even if the DB doesn't exist
And start using flyway for the migrations (first tables, etc)...
After that I could switch ddl-auto to none.
What would be the flow?