Issue
I have a Quarkus app that I deploy in OpenShift. application.properties includes the following config:
quarkus.datasource.db-kind=h2
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.datasource.jdbc.url=jdbc:h2:mem:default
quarkus.smallrye-graphql.ui.always-include=true
This configuration results in schema being effectively created. However the database is not populated. All tables are empty. It seems import.sql is ignored.
To avoid this, I tried following:
quarkus.datasource.jdbc.url=jdbc:h2:mem:default;INIT=RUNSCRIPT FROM 'classpath:import.sql'
This results in the import.sql indeed being executed. However this execution is happening before the schema is generated, causing a tome of errors that say that tables do not exist.
How do I resolve this? Outside of OpenShift the first configuration above works as expected.
Solution
In prod mode, the import.sql
is not read (on purpose).
If you still want to load the data, you need to add:
%prod.quarkus.hibernate-orm.sql-load-script=import.sql
By default, this property is set to no-file
.
Note that you can use a different file name in prod
if you need.
Answered By - Clement
Answer Checked By - Candace Johnson (JavaFixing Volunteer)