Skip to content

Commit

Permalink
Merge pull request #799 from woowacourse-teams/refactor/744-dev-db-se…
Browse files Browse the repository at this point in the history
…tting

DataSourceConfig를 모든 환경에 적용되도록 변경
  • Loading branch information
zeus6768 authored Oct 17, 2024
2 parents 77a05f4 + ffd898f commit 7535f77
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 36 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/backend_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ jobs:
mysql version: ${{ secrets.MYSQL_VERSION }}
mysql database: ${{ secrets.MYSQL_DATABASE }}
mysql root password: ${{ secrets.MYSQL_PASSWORD }}

- name: DB 설정 파일 가져오기
working-directory: ./backend/src/main/resources
run: echo "${{ secrets.APPLICATION_DB_YAML }}" > application-db.yml


- name: gradle 캐싱
uses: gradle/actions/setup-gradle@v4

Expand All @@ -36,6 +32,10 @@ jobs:
java-version: 17
distribution: temurin

- name: 환경변수 주입
run: ${{ secrets.APPLICATION_YML }}
working-directory: ./backend/src/test/resources

- name: 테스트 코드 실행
run: ./gradlew test
working-directory: ./backend
2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ out/
.DS_Store

### YAML ###
application-db.yml
src/test/resources/application.yml

### compose ###
docker/app/*.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

@Configuration
@RequiredArgsConstructor
@Profile("prod")
@EnableJpaRepositories(basePackages = "codezap")
public class DataSourceConfig {

Expand Down
23 changes: 23 additions & 0 deletions backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,28 @@ spring:
output:
ansi:
enabled: always
datasource:
write:
jdbc-url: ${MYSQL_WRITER_URL}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
read:
jdbc-url: ${MYSQL_READER_URL}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
flyway:
enabled: false
locations: classpath:db/migration
jpa:
# open-in-view: false
hibernate:
ddl-auto: create
properties:
hibernate:
dialect: codezap.template.repository.FullTextSearchMySQLDialect
data.web.pageable.one-indexed-parameters: true

cors:
allowed-origins: http://localhost:3000
1 change: 0 additions & 1 deletion backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ spring:
profiles:
active:
- local
- db
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

import codezap.global.DatabaseIsolation;
import codezap.global.auditing.JpaAuditingConfiguration;
import codezap.global.rds.DataSourceConfig;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@DataJpaTest
@DatabaseIsolation
@Import(JpaAuditingConfiguration.class)
@Import({JpaAuditingConfiguration.class, DataSourceConfig.class})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public @interface JpaRepositoryTest {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
import codezap.category.domain.Category;
import codezap.category.repository.CategoryRepository;
import codezap.global.auditing.JpaAuditingConfiguration;
import codezap.global.rds.DataSourceConfig;
import codezap.member.domain.Member;
import codezap.member.repository.MemberRepository;
import codezap.tag.domain.Tag;
import codezap.tag.repository.TagRepository;
import codezap.template.domain.Template;

@DataJpaTest
@Import(JpaAuditingConfiguration.class)
@Import({JpaAuditingConfiguration.class, DataSourceConfig.class})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@Sql(scripts = "classpath:search.sql", executionPhase = ExecutionPhase.BEFORE_TEST_CLASS)
class TemplateSearchJpaRepositoryTest {
Expand Down
6 changes: 0 additions & 6 deletions backend/src/test/resources/application-local.yml

This file was deleted.

5 changes: 0 additions & 5 deletions backend/src/test/resources/application.yml

This file was deleted.

15 changes: 0 additions & 15 deletions backend/src/test/resources/clear.sql

This file was deleted.

0 comments on commit 7535f77

Please sign in to comment.