fix: refactor ClickHouse config to match cameleer3-server pattern
All checks were successful
CI / build (push) Successful in 38s
CI / docker (push) Successful in 32s

- Add ClickHouseProperties with @ConfigurationProperties
- @ConditionalOnProperty to toggle ClickHouse
- @Primary DataSource + JdbcTemplate for PostgreSQL (prevents Spring
  Boot from routing JPA/Flyway to ClickHouse)
- HikariDataSource for ClickHouse with explicit credentials
- Remove separate DataSourceConfig.java (merged into ClickHouseConfig)
- Remove database-platform override (no longer needed with @Primary)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-04 23:09:01 +02:00
parent be4c882ef8
commit 032db410c7
4 changed files with 68 additions and 10 deletions

View File

@@ -1,23 +1,48 @@
package net.siegeln.cameleer.saas.log; package net.siegeln.cameleer.saas.log;
import org.springframework.beans.factory.annotation.Value; import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import com.clickhouse.jdbc.ClickHouseDataSource; import javax.sql.DataSource;
import java.util.Properties;
@Configuration @Configuration
@Profile("!test") @EnableConfigurationProperties(ClickHouseProperties.class)
@ConditionalOnProperty(name = "cameleer.clickhouse.enabled", havingValue = "true", matchIfMissing = true)
public class ClickHouseConfig { public class ClickHouseConfig {
@Value("${cameleer.clickhouse.url:jdbc:clickhouse://clickhouse:8123/cameleer}") /**
private String url; * Explicit primary PG DataSource. Required because adding a second DataSource
* (ClickHouse) prevents Spring Boot auto-configuration from creating the default one.
*/
@Bean
@Primary
public DataSource dataSource(DataSourceProperties properties) {
return properties.initializeDataSourceBuilder().build();
}
@Bean
@Primary
public JdbcTemplate jdbcTemplate(@Qualifier("dataSource") DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "clickHouseDataSource") @Bean(name = "clickHouseDataSource")
public ClickHouseDataSource clickHouseDataSource() throws Exception { public DataSource clickHouseDataSource(ClickHouseProperties props) {
var properties = new Properties(); HikariDataSource ds = new HikariDataSource();
return new ClickHouseDataSource(url, properties); ds.setJdbcUrl(props.getUrl());
ds.setUsername(props.getUsername());
ds.setPassword(props.getPassword());
ds.setMaximumPoolSize(10);
ds.setMinimumIdle(2);
ds.setConnectionTimeout(5000);
ds.setPoolName("clickhouse-pool");
return ds;
} }
} }

View File

@@ -0,0 +1,24 @@
package net.siegeln.cameleer.saas.log;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "cameleer.clickhouse")
public class ClickHouseProperties {
private boolean enabled = true;
private String url = "jdbc:clickhouse://clickhouse:8123/cameleer";
private String username = "default";
private String password = "";
public boolean isEnabled() { return enabled; }
public void setEnabled(boolean enabled) { this.enabled = enabled; }
public String getUrl() { return url; }
public void setUrl(String url) { this.url = url; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
}

View File

@@ -9,6 +9,12 @@ spring:
url: jdbc:postgresql://localhost:5432/cameleer_saas url: jdbc:postgresql://localhost:5432/cameleer_saas
user: cameleer user: cameleer
password: cameleer_dev password: cameleer_dev
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://localhost:3001/oidc
jwk-set-uri: http://localhost:3001/oidc/jwks
cameleer: cameleer:
clickhouse: clickhouse:

View File

@@ -54,4 +54,7 @@ cameleer:
cameleer3-server-endpoint: ${CAMELEER3_SERVER_ENDPOINT:http://cameleer3-server:8081} cameleer3-server-endpoint: ${CAMELEER3_SERVER_ENDPOINT:http://cameleer3-server:8081}
domain: ${DOMAIN:localhost} domain: ${DOMAIN:localhost}
clickhouse: clickhouse:
enabled: ${CLICKHOUSE_ENABLED:true}
url: ${CLICKHOUSE_URL:jdbc:clickhouse://clickhouse:8123/cameleer} url: ${CLICKHOUSE_URL:jdbc:clickhouse://clickhouse:8123/cameleer}
username: ${CLICKHOUSE_USERNAME:default}
password: ${CLICKHOUSE_PASSWORD:}