diff --git a/docker/demo.yaml b/docker/demo.yaml index 1a4b03778..5b930b920 100644 --- a/docker/demo.yaml +++ b/docker/demo.yaml @@ -17,9 +17,6 @@ services: - SPRING_DATASOURCE_URL=jdbc:postgresql://database:5432/${POSTGRES_DATABASE} - SPRING_DATASOURCE_USERNAME=${POSTGRES_USER} - SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD} - - SPRING_CUSTOM-DATASOURCE_URL=jdbc:postgresql://database:5432/${POSTGRES_DATABASE}?schema=lookup_tables_schema - - SPRING_CUSTOM-DATASOURCE_USERNAME=${POSTGRES_USER} - - SPRING_CUSTOM-DATASOURCE_PASSWORD=${POSTGRES_PASSWORD} depends_on: - database ports: diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/config/R2DBCConfiguration.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/config/R2DBCConfiguration.java index 2d91748ae..6e905a728 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/config/R2DBCConfiguration.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/config/R2DBCConfiguration.java @@ -5,6 +5,7 @@ import io.r2dbc.spi.ConnectionFactories; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryOptions; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; @@ -19,6 +20,7 @@ @Configuration public class R2DBCConfiguration { + public static final String SCHEMA_PART_FOR_DB_URL = "?schema=lookup_tables_schema"; @Bean(destroyMethod = "dispose") @Primary @@ -49,15 +51,21 @@ public ConnectionPool connectionFactory(final DataSourceProperties dataSourcePro @Bean(name = "customConnectionPool", destroyMethod = "dispose") public ConnectionPool databaseClientForCustomSchema( - @Value("${spring.custom-datasource.url}") final String url, - @Value("${spring.custom-datasource.username}") final String username, - @Value("${spring.custom-datasource.password}") final String password, + @Value("${spring.custom-datasource.url:}") final String url, + @Value("${spring.custom-datasource.username:}") final String username, + @Value("${spring.custom-datasource.password:}") final String password, + final DataSourceProperties dataSourceProperties, final R2dbcProperties properties) { - final String r2dbcUrl = url.replace("jdbc", "r2dbc"); + final String finalDBUrl = + (StringUtils.isBlank(url) ? dataSourceProperties.getUrl() : url) + SCHEMA_PART_FOR_DB_URL; + final String finalDBUsername = StringUtils.isBlank(username) ? dataSourceProperties.getUsername() : username; + final String finalDBPassword = StringUtils.isBlank(password) ? dataSourceProperties.getPassword() : password; + + final String r2dbcUrl = finalDBUrl.replace("jdbc", "r2dbc"); final ConnectionFactory factory = ConnectionFactories.get(ConnectionFactoryOptions.parse(r2dbcUrl).mutate() .option(ConnectionFactoryOptions.PROTOCOL, "postgresql") - .option(ConnectionFactoryOptions.USER, username) - .option(ConnectionFactoryOptions.PASSWORD, password) + .option(ConnectionFactoryOptions.USER, finalDBUsername) + .option(ConnectionFactoryOptions.PASSWORD, finalDBPassword) .build()); final R2dbcProperties.Pool pool = properties.getPool(); diff --git a/odd-platform-api/src/main/resources/application.yml b/odd-platform-api/src/main/resources/application.yml index 472359bbd..dd05d2cfb 100644 --- a/odd-platform-api/src/main/resources/application.yml +++ b/odd-platform-api/src/main/resources/application.yml @@ -5,10 +5,10 @@ spring: url: jdbc:postgresql://127.0.0.1:5432/odd-platform username: odd-platform password: odd-platform-password - custom-datasource: - url: jdbc:postgresql://127.0.0.1:5432/odd-platform?schema=lookup_tables_schema - username: odd-platform - password: odd-platform-password +# custom-datasource: +# url: jdbc:postgresql://127.0.0.1:5432/odd-platform +# username: odd-platform +# password: odd-platform-password jooq: sql-dialect: postgres codec: