Skip to content

Conversation

@sukangpunch
Copy link
Contributor

@sukangpunch sukangpunch commented Jan 19, 2026

관련 이슈

작업 내용

@FlywayDataSource 를 활용하여 flyway 전용 DataSource를 추가하였습니다.

특이 사항

원인
Flyway 설정(user, password)과 애플리케이션 DataSource 설정(username, password)이 다른 상황에서,
Flyway AutoConfiguration이 별도 DataSource를 생성하기 위해 DataSourceBuilder를 사용했습니다.

그런데 기존 proxyDataSource가 DataSourceProperties.initializeDataSourceBuilder()를 사용하여
Proxy 관련 타입 정보가 포함된 상태였고, 이로 인해 Flyway의 DataSourceBuilder가
url setter 메서드를 찾지 못하는 에러가 발생했습니다.

해결
@FlywayDataSource 어노테이션으로 Flyway 전용 DataSource Bean을 명시적으로 생성하여,
Flyway AutoConfiguration이 DataSourceBuilder를 통해 DataSource를 자체 생성하지 않고
직접 만든 완성된 DataSource를 사용하도록 하여 문제를 해결했습니다.

리뷰 요구사항 (선택)

@sukangpunch sukangpunch self-assigned this Jan 19, 2026
@sukangpunch sukangpunch added the 버그 Something isn't working label Jan 19, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2026

Walkthrough

1. 새로운 DataSourceConfig 클래스가 추가되어 두 개의 빈을 정의합니다.
2.  proxyDataSource(DataSourceProperties) 빈은 properties로 기본 DataSource를 생성해 ProxyDataSourceBuilder로 감싸고 QueryMetricsListener를 연결한 뒤 이름을 "main"으로 설정합니다.
3.  flywayDataSource(...) 빈은 Flyway 전용 HikariDataSource를 URL/사용자/비밀번호로 구성하고 고정 MySQL 드라이버 및 풀 설정(최소 유휴, 최대 풀 크기, 연결/유휴/최대 수명 타임아웃 등)을 적용합니다.
4. 기존의 DataSourceProxyConfig 클래스와 그 안의 proxyDataSource 빈 정의는 삭제되어 해당 파일과 이전 구현이 제거되었습니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Suggested reviewers

  • wibaek
  • Hexeong
  • JAEHEE25
  • lsy1307
  • Gyuhyeok99
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목은 Flyway 전용 DataSource 설정 변경이라는 핵심 내용을 명확하고 간결하게 요약하고 있습니다.
Description check ✅ Passed PR 설명은 관련 이슈, 작업 내용, 특이사항을 모두 포함하며 문제 원인과 해결 방법을 상세히 기술하고 있습니다.
Linked Issues check ✅ Passed PR의 코드 변경사항이 #612의 요구사항을 충족합니다: @FlywayDataSource 어노테이션으로 Flyway 전용 DataSource를 명시적으로 생성하여 자격증명 불일치 문제를 해결했습니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 Flyway DataSource 설정 문제 해결이라는 범위 내에서 진행되었으며, 불필요한 추가 수정은 없습니다.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- 테스트 환경에서 flyway.user 미설정 시에도 정상 동작하도록 수정
@sukangpunch sukangpunch force-pushed the fix/612-flyway-datasource-config branch from 65dbd91 to 2bb7a61 Compare January 19, 2026 16:19
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@src/main/java/com/example/solidconnection/common/config/datasource/DataSourceConfig.java`:
- Around line 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.

Comment on lines 36 to 52
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

@whqtker whqtker left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 ~ 집 가서 한 번 테스트해보겠습니다 ..!

추가로 서브모듈 해시 커밋도 있는데, 잘못 포함된건가요 ?

dataSource.setMaximumPoolSize(2);
dataSource.setConnectionTimeout(10000);
dataSource.setIdleTimeout(60000); // 1분으로 단축
dataSource.setMaxLifetime(300000); // 최대 5분
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.

수정하겠습니다!

@sukangpunch
Copy link
Contributor Author

고생하셨습니다 ~ 집 가서 한 번 테스트해보겠습니다 ..!

추가로 서브모듈 해시 커밋도 있는데, 잘못 포함된건가요 ?

잘못 포함되었네요! 수정하겠습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

버그 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: flyway datasource 문제 수정

2 participants