-
Notifications
You must be signed in to change notification settings - Fork 8
fix: flyway 전용 DataSource를 사용하도록 수정 #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
fix: flyway 전용 DataSource를 사용하도록 수정 #613
Conversation
Walkthrough1. 새로운 Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
- 테스트 환경에서 flyway.user 미설정 시에도 정상 동작하도록 수정
65dbd91 to
2bb7a61
Compare
There was a problem hiding this 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.
| 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분 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 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 -80Repository: 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 -20Repository: 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 2Repository: 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 -100Repository: solid-connection/solid-connect-server
Length of output: 713
🏁 Script executed:
# Also check test configuration
cat -n src/test/resources/application.yml | head -100Repository: 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 yamlRepository: 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가 표준 설정 프로퍼티를 무시합니다
현재 구현은 두 가지 설정 문제를 가지고 있습니다:
-
spring.flyway.url 무시
- 비록 매개변수에서
spring.flyway.user와spring.flyway.password는 오버라이드를 지원하지만, URL은 항상spring.datasource.url만 사용됩니다. - Spring Boot 표준에 따르면,
spring.flyway.url을 설정하면 Flyway가 자체 DataSource를 사용해야 합니다.
- 비록 매개변수에서
-
드라이버 클래스 하드코딩
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.
whqtker
left a comment
There was a problem hiding this 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분 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 매직넘버들 상수로 분리하거나 설정 파일로 분리하는 것도 좋아 보입니다 !
관련 이슈
작업 내용
@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를 사용하도록 하여 문제를 해결했습니다.
리뷰 요구사항 (선택)