Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.example.solidconnection.common.config.datasource;

import com.example.solidconnection.common.listener.QueryMetricsListener;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import lombok.RequiredArgsConstructor;
import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.flyway.FlywayDataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@RequiredArgsConstructor
@Configuration
public class DataSourceConfig {

private final QueryMetricsListener queryMetricsListener;

@Bean
@Primary
public DataSource proxyDataSource(DataSourceProperties props) {
DataSource dataSource = props.initializeDataSourceBuilder().build();

return ProxyDataSourceBuilder
.create(dataSource)
.listener(queryMetricsListener)
.name("main")
.build();
}

// Flyway 전용 DataSource (Proxy 미적용)
@Bean
@FlywayDataSource
public DataSource flywayDataSource(
@Value("${spring.datasource.url}") String url,
@Value("${spring.flyway.user:${spring.datasource.username}}") String username,
@Value("${spring.flyway.password:${spring.datasource.password}}") String password
) {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setJdbcUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setPoolName("FlywayPool");

dataSource.setMinimumIdle(0);
dataSource.setMaximumPoolSize(2);
dataSource.setConnectionTimeout(10000);
dataSource.setIdleTimeout(60000); // 1분으로 단축
dataSource.setMaxLifetime(300000); // 최대 5분
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the actual file to confirm the current implementation
cat -n src/main/java/com/example/solidconnection/common/config/datasource/DataSourceConfig.java | head -80

Repository: solid-connection/solid-connect-server

Length of output: 2578


🏁 Script executed:

# Search for application properties files
find . -name "application*.properties" -o -name "application*.yml" -o -name "application*.yaml" | head -20

Repository: solid-connection/solid-connect-server

Length of output: 154


🏁 Script executed:

# Search for any references to spring.flyway properties in the codebase
rg "spring\.flyway\." --type java --type yaml --type properties -A 2

Repository: solid-connection/solid-connect-server

Length of output: 115


🏁 Script executed:

# Check the application.yml to see what properties are configured
cat -n src/main/resources/application.yml | head -100

Repository: solid-connection/solid-connect-server

Length of output: 713


🏁 Script executed:

# Also check test configuration
cat -n src/test/resources/application.yml | head -100

Repository: solid-connection/solid-connect-server

Length of output: 3007


🏁 Script executed:

# Search for any documentation or comments about Flyway in the codebase
rg "flyway|Flyway" -B 2 -A 2 --type java --type yaml

Repository: solid-connection/solid-connect-server

Length of output: 6233


🌐 Web query:

Spring Boot Flyway datasource properties spring.flyway.url spring.flyway.driver-class-name

💡 Result:

  • spring.flyway.url — if set, Flyway will create and use its own DataSource for migrations (instead of the autowired spring.datasource). You usually set spring.flyway.url, spring.flyway.user and spring.flyway.password when you want Flyway to connect with different credentials or a different DB. [1][2]

  • spring.flyway.driver-class-name — optional; fully qualified JDBC driver class name. Spring Boot will auto-detect the driver from the JDBC URL, but set this property to remove ambiguity (multiple drivers on the classpath) or if auto-detection fails. [2]

Example (application.properties):
spring.datasource.url=jdbc:postgresql://localhost:5432/appdb
spring.datasource.username=app
spring.datasource.password=appPass

Flyway uses its own connection (can be same or different)

spring.flyway.url=jdbc:postgresql://localhost:5432/migrationsdb
spring.flyway.user=flyway
spring.flyway.password=flywayPass
spring.flyway.driver-class-name=org.postgresql.Driver

References:
[1] Spring Boot reference — Flyway support (explains that setting spring.flyway.url/user causes Flyway to use its own DataSource).
[2] Spring Boot application-properties appendix — spring.flyway.driver-class-name (auto-detected by default).


🌐 Web query:

Spring Boot FlywayProperties standard configuration properties

💡 Result:

See the Spring Boot Flyway configuration reference and the FlywayProperties API for the canonical list of supported spring.flyway.* properties. Key entry points:

  • Spring Boot How-to / Flyway integration (explanation and examples). [1]
  • FlywayProperties API (full set of properties exposed by Spring Boot’s spring.flyway prefix). [2]

If you want, I can enumerate the common properties (spring.flyway.enabled, locations, baselineOnMigrate, baselineVersion, validateOnMigrate, outOfOrder, schemas, table, encoding, connectRetries, placeholders, sqlMigrationPrefix/suffix, skipDefaultCallbacks, skipDefaultResolvers, etc.) with exact names and brief meanings drawn from the API/docs — shall I list them in one response?


Flyway 전용 DataSource가 표준 설정 프로퍼티를 무시합니다

현재 구현은 두 가지 설정 문제를 가지고 있습니다:

  1. spring.flyway.url 무시

    • 비록 매개변수에서 spring.flyway.userspring.flyway.password는 오버라이드를 지원하지만, URL은 항상 spring.datasource.url만 사용됩니다.
    • Spring Boot 표준에 따르면, spring.flyway.url을 설정하면 Flyway가 자체 DataSource를 사용해야 합니다.
  2. 드라이버 클래스 하드코딩

    • com.mysql.cj.jdbc.Driver로 고정되어 있어 PostgreSQL, Oracle 등 다른 데이터베이스 환경에서는 즉시 실패합니다.
    • Spring Boot는 JDBC URL에서 드라이버를 자동 감지할 수 있으며, spring.flyway.driver-class-name 프로퍼티로 명시할 수도 있습니다.

다음과 같이 수정하여 표준 설정 오버라이드를 활성화해 주세요:

🛠️ 제안 변경
-    public DataSource flywayDataSource(
-            `@Value`("${spring.datasource.url}") String url,
-            `@Value`("${spring.flyway.user:${spring.datasource.username}}") String username,
-            `@Value`("${spring.flyway.password:${spring.datasource.password}}") String password
-    ) {
+    public DataSource flywayDataSource(
+            `@Value`("${spring.flyway.url:${spring.datasource.url}}") String url,
+            `@Value`("${spring.flyway.driver-class-name:${spring.datasource.driver-class-name:}}") String driverClassName,
+            `@Value`("${spring.flyway.user:${spring.datasource.username}}") String username,
+            `@Value`("${spring.flyway.password:${spring.datasource.password}}") String password
+    ) {
         HikariDataSource dataSource = new HikariDataSource();
         dataSource.setJdbcUrl(url);
         dataSource.setUsername(username);
         dataSource.setPassword(password);
-        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
+        if (driverClassName != null && !driverClassName.isBlank()) {
+            dataSource.setDriverClassName(driverClassName);
+        }
         dataSource.setPoolName("FlywayPool");
🤖 Prompt for AI Agents
In
`@src/main/java/com/example/solidconnection/common/config/datasource/DataSourceConfig.java`
around lines 36 - 52, The flywayDataSource method currently ignores
spring.flyway.url and hardcodes the driver; update the method signature to
accept a flywayUrl and optional flywayDriver property (e.g.
`@Value`("${spring.flyway.url:${spring.datasource.url}}") String url,
`@Value`("${spring.flyway.driver-class-name:}") String driver) so the URL can be
overridden by spring.flyway.url, set the HikariDataSource JDBC URL from that
parameter, and only call dataSource.setDriverClassName(...) when the driver
string is non-empty (or allow it to be omitted so the driver is auto-detected
from the JDBC URL); keep other pool settings on HikariDataSource as-is and
reference the flywayDataSource method and HikariDataSource#setDriverClassName
when making changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 매직넘버들 상수로 분리하거나 설정 파일로 분리하는 것도 좋아 보입니다 !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하겠습니다!


return dataSource;
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/secret
Loading