Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quarkus datasource with Heroku

I'm trying to deploy my Quarkus-app on Heroku. It works fine, but I needed to specify the datasource-parameters with fix values. Because Heroku might rotate this parameters, this is not a really good idea.

In Quarkus, I need this 3 parameters in application.properties:

quarkus.datasource.username
quarkus.datasource.password
quarkus.datasource.jdbc.url

Heroku only gives me 1 environment variable (DATABASE_URL), which defines a connection-string in the following manner: postgres://user:pass@server:port/db-name

I know I can use environment variables like so: quarkus.datasource.jdbc.url = jdbc:${DATABASE_URL}

But I need to split up the variable to extract user and password and to change prefix (postgresql instead of postgres).

Does anyone have an idea how to achieve this?

like image 380
Simon Wick Avatar asked Apr 03 '20 09:04

Simon Wick


People also ask

How does the Heroku Dev database work?

The dev database is meant for testing purposes. For a production application you must use one of the Heroku Postgres databases or SQL add-ons. Once you have provisioned a relational database to your application. The application reads the database connection information from the DATABASE_URL config variable. It is formatted like this:

What is the difference between Heroku and Quarkus Maven?

The first variant uses the Quarkus Maven build to create the quarkus-app application structure containing the runnable "fast-jar" as well as all libraries needed inside Heroku’s build infrastructure and then deploying that result, the other one uses a local build process to create an optimized container.

Which database should I use with Quarkus?

If you prefer using a reactive datasource, Quarkus offers DB2, MySQL/MariaDB, and PostgreSQL reactive clients. Depending on which database you want to use, add the corresponding extension:

Does Quarkus support DataSource without CONFIG?

As mentioned above Quarkus supports a feature called Dev Services that allows you to create datasources without any config.


1 Answers

You can use the JDBC_DATABASE_URL, JDBC_DATABASE_USERNAME and JDBC_DATABASE_PASSWORD environment variables for your use-case.

For more details, you can find the documentation here: https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#using-the-jdbc_database_url

like image 183
Malax Avatar answered Oct 09 '22 14:10

Malax