fix: refactor ClickHouse config to match cameleer3-server pattern
- 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:
@@ -1,23 +1,48 @@
|
||||
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.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 java.util.Properties;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
@Profile("!test")
|
||||
@EnableConfigurationProperties(ClickHouseProperties.class)
|
||||
@ConditionalOnProperty(name = "cameleer.clickhouse.enabled", havingValue = "true", matchIfMissing = true)
|
||||
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")
|
||||
public ClickHouseDataSource clickHouseDataSource() throws Exception {
|
||||
var properties = new Properties();
|
||||
return new ClickHouseDataSource(url, properties);
|
||||
public DataSource clickHouseDataSource(ClickHouseProperties props) {
|
||||
HikariDataSource ds = new HikariDataSource();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -9,6 +9,12 @@ spring:
|
||||
url: jdbc:postgresql://localhost:5432/cameleer_saas
|
||||
user: cameleer
|
||||
password: cameleer_dev
|
||||
security:
|
||||
oauth2:
|
||||
resourceserver:
|
||||
jwt:
|
||||
issuer-uri: http://localhost:3001/oidc
|
||||
jwk-set-uri: http://localhost:3001/oidc/jwks
|
||||
|
||||
cameleer:
|
||||
clickhouse:
|
||||
|
||||
@@ -54,4 +54,7 @@ cameleer:
|
||||
cameleer3-server-endpoint: ${CAMELEER3_SERVER_ENDPOINT:http://cameleer3-server:8081}
|
||||
domain: ${DOMAIN:localhost}
|
||||
clickhouse:
|
||||
enabled: ${CLICKHOUSE_ENABLED:true}
|
||||
url: ${CLICKHOUSE_URL:jdbc:clickhouse://clickhouse:8123/cameleer}
|
||||
username: ${CLICKHOUSE_USERNAME:default}
|
||||
password: ${CLICKHOUSE_PASSWORD:}
|
||||
|
||||
Reference in New Issue
Block a user