diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/DatabasePropertyMappers.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/DatabasePropertyMappers.java index bee180f30b..ffd6a72b5e 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/DatabasePropertyMappers.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/configuration/mappers/DatabasePropertyMappers.java @@ -47,12 +47,25 @@ final class DatabasePropertyMappers { .to("quarkus.datasource.jdbc.url") .mapFrom("db") .transformer((value, context) -> Database.getDefaultUrl(value).orElse(value)) - .description("The database JDBC URL. If not provided, a default URL is set based on the selected database vendor. " + - "For instance, if using 'postgres', the JDBC URL would be 'jdbc:postgresql://localhost/keycloak'. " + - "The host, database and properties can be overridden by setting the following system properties," + - " respectively: -Dkc.db.url.host, -Dkc.db.url.database, -Dkc.db.url.properties.") + .description("The full database JDBC URL. If not provided, a default URL is set based on the selected database vendor. " + + "For instance, if using 'postgres', the default JDBC URL would be 'jdbc:postgresql://localhost/keycloak'. ") .paramLabel("jdbc-url") .build(), + builder().from("db.url.host") + .to("kc.db.url.host") + .description("Sets the hostname of the default JDBC URL of the chosen vendor. If the `db-url` option is set, this option is ignored.") + .paramLabel("hostname") + .build(), + builder().from("db.url.database") + .to("kc.db.url.database") + .description("Sets the database name of the default JDBC URL of the chosen vendor. If the `db-url` option is set, this option is ignored.") + .paramLabel("dbname") + .build(), + builder().from("db.url.properties") + .to("kc.db.url.properties") + .description("Sets the properties of the default JDBC URL of the chosen vendor. If the `db-url` option is set, this option is ignored.") + .paramLabel("properties") + .build(), builder().from("db.username") .to("quarkus.datasource.username") .description("The username of the database user.") diff --git a/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java b/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java index dd285bf8e6..29f1e5118e 100644 --- a/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java +++ b/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java @@ -253,6 +253,26 @@ public class ConfigurationTest { assertEquals("postgresql", config.getConfigValue("quarkus.datasource.db-kind").getValue()); } + @Test + public void testDefaultDbPropertiesGetApplied() { + System.setProperty(CLI_ARGS, "--db=postgres" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url-database=kcdb" + ARG_SEPARATOR + "--db-url-properties=?foo=bar"); + SmallRyeConfig config = createConfig(); + assertEquals("io.quarkus.hibernate.orm.runtime.dialect.QuarkusPostgreSQL10Dialect", + config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); + assertEquals("jdbc:postgresql://myhost/kcdb?foo=bar", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); + assertEquals("postgresql", config.getConfigValue("quarkus.datasource.db-kind").getValue()); + } + + @Test + public void testSetDbUrlOverridesDefaultDataSource() { + System.setProperty(CLI_ARGS, "--db=mariadb" + ARG_SEPARATOR + "--db-url-host=myhost" + ARG_SEPARATOR + "--db-url=jdbc:mariadb://localhost/keycloak"); + SmallRyeConfig config = createConfig(); + assertEquals("org.hibernate.dialect.MariaDBDialect", + config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); + assertEquals("jdbc:mariadb://localhost/keycloak", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); + assertEquals("mariadb", config.getConfigValue("quarkus.datasource.db-kind").getValue()); + } + @Test public void testDatabaseProperties() { System.setProperty("kc.db.url.properties", ";;test=test;test1=test1");