Skip to content
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

fix/feat: flyway V5 DML이 적용되지 않는 문제 해결 + 테스트 컨테이너 적용 #729

Merged
merged 21 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8c438e1
test: 테스트 컨테이너 적용
hyeon0208 Oct 14, 2024
c57e32d
style: 컨벤션 적용
hyeon0208 Oct 14, 2024
06fe165
chore: gradle compose 플러그인 적용
hyeon0208 Oct 15, 2024
c3a9fc3
chore: local용 db 연결 설정
hyeon0208 Oct 15, 2024
338dad1
test: ddl-auto 설정 변경
hyeon0208 Oct 15, 2024
0679e5e
test: 데이터 클리너 로직 수정
hyeon0208 Oct 15, 2024
14dfea0
chore: fly 스키마 파일 변경
hyeon0208 Oct 15, 2024
f89c094
refactor: 테스트컨테이너 타임존 설정 추가
hyeon0208 Oct 15, 2024
6131e97
chore: git action runner 타임존 출력
hyeon0208 Oct 16, 2024
7270bd8
chore: git action runner 타임존 한국으로 설정
hyeon0208 Oct 16, 2024
54f53db
chore: 테스트 컨테이너 타임존 한국으로 설정
hyeon0208 Oct 16, 2024
b871c2d
chore: 애플리케이션 DB 컨테이너 TZ 한국으로 설정
hyeon0208 Oct 16, 2024
671b5f0
chore: DB 컨테이너 스크립트로 초기화되도록 수정
hyeon0208 Oct 16, 2024
7081022
chore: DB 컨테이너 실행 커맨드 수정
hyeon0208 Oct 16, 2024
2b445eb
chore: dev, prod ci jops 타임존 설정
hyeon0208 Oct 16, 2024
06c488f
chore: 프로필 별 flyway 설정 적용
hyeon0208 Oct 16, 2024
ad794e6
chore: 의존성 컨벤션 적용
hyeon0208 Oct 16, 2024
16acd52
test: h2를 사용한 테스트로 롤백
hyeon0208 Oct 16, 2024
635a173
chore: 테스트 컨테이너 설정 클래스 제거
hyeon0208 Oct 17, 2024
c9cc986
chore: 테스트 컨테이너 의존성 제거
hyeon0208 Oct 17, 2024
ba34a94
chore: ci/cd 스크립트 타임존 설정 및 시간 체크
hyeon0208 Oct 17, 2024
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
8 changes: 7 additions & 1 deletion .github/workflows/backend-ci-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ on:

jobs:
build-and-push:

runs-on: ubuntu-latest
env:
TZ: 'Asia/Seoul'

defaults:
run:
Expand All @@ -25,6 +26,11 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Check system timezone
run: |
echo "Current date and time: $(date)"
echo "TZ environment variable: $TZ"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/backend-ci-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: backend-ci-dev
name: backend-ci-prod

on:
pull_request:
Expand All @@ -9,8 +9,9 @@ on:

jobs:
build-and-push:

runs-on: ubuntu-latest
env:
TZ: 'Asia/Seoul'
Comment on lines +13 to +14
Copy link
Contributor

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.

모든 job들에 타임존 설정이 적용되고 있어서
시간 계산 로직으로 인한 사이드 이펙트 방지로 들어가면 좋을꺼같아요 !


defaults:
run:
Expand Down
90 changes: 47 additions & 43 deletions backend/build.gradle
Original file line number Diff line number Diff line change
@@ -1,76 +1,80 @@
plugins {
id 'java'
id 'jacoco' //테스트 커버리지 검증 라이브러리 추가
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'java'
id 'jacoco' //테스트 커버리지 검증 라이브러리 추가
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'com.palantir.docker-compose' version '0.36.0'
}

group = 'com.ody'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}

dockerCompose {
dockerComposeFile 'docker-compose-local.yml'
}

jacoco {
toolVersion = '0.8.8'
toolVersion = '0.8.8'
}

jacocoTestReport {
jacocoTestReport {
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(true)
}
}
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(true)
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
implementation 'com.google.firebase:firebase-admin:9.2.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation "io.jsonwebtoken:jjwt:0.9.1"
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'org.springframework.boot:spring-boot-starter-actuator'

runtimeOnly 'com.mysql:mysql-connector-j:8.4.0'
runtimeOnly 'com.h2database:h2'
implementation 'com.google.firebase:firebase-admin:9.2.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation "io.jsonwebtoken:jjwt:0.9.1"
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.flywaydb:flyway-mysql'
implementation 'org.flywaydb:flyway-core'
implementation 'org.testcontainers:testcontainers-bom:1.20.2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:5.3.1'
runtimeOnly 'com.mysql:mysql-connector-j:8.4.0'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testRuntimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.rest-assured:rest-assured:5.3.1'
testImplementation "org.testcontainers:junit-jupiter"
testImplementation 'org.testcontainers:mysql'

annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
testRuntimeOnly 'com.h2database:h2'

implementation 'org.flywaydb:flyway-mysql'
implementation 'org.flywaydb:flyway-core'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
}

tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport
useJUnitPlatform()
finalizedBy jacocoTestReport
}

configurations.all {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'commons-logging', module: 'commons-logging'
}
12 changes: 12 additions & 0 deletions backend/docker-compose-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
db:
image: mysql:8.0.35
container_name: mysql-local-db
restart: always
ports:
- "53306:3306"
environment:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: 1234
MYSQL_DATABASE: ody
TZ: Asia/seoul
34 changes: 0 additions & 34 deletions backend/docker-compose.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public interface EtaRepository extends JpaRepository<Eta, Long> {
Optional<Eta> findByMateId(Long id);

@Query("""
select e from Eta e
join Mate ma on e.mate.id = ma.id
join Meeting me on e.mate.meeting.id = me.id
where me.id = :meetingId
select e from Eta e
join Mate ma on e.mate.id = ma.id
join Meeting me on e.mate.meeting.id = me.id
where me.id = :meetingId
""")
List<Eta> findAllByMeetingId(Long meetingId);
}
5 changes: 2 additions & 3 deletions backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ spring:
jpa:
hibernate:
ddl-auto: validate
sql:
init:
mode: never
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ENC(KUJNgDMlvi/imeVHjCO2QekgI4DNxZT9IrW0QlVVkJXJUUQ2DAUOqI91FVH7aFhXVCsfXtf0EUmF/JqN3GpXa/mVj3o4BNbqS3QsU50BgwEEodko+VwHY2ebDHUxlKA1/FXBSmu6p+Rd3rcNEzoBIA==)
username: ENC(jNYhZN6xMCmPQ7GZM+Hu3A==)
password: ENC(VRtr3RjM+XnPvRdLjrPMHyTSzDlEjR7o)
flyway:
baseline-version: 2

log:
file:
Expand Down
23 changes: 9 additions & 14 deletions backend/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
spring:
h2:
console:
enabled: true
path: /h2-console
settings:
web-allow-others: true
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:database?serverTimezone=Asia/Seoul;MODE=MYSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=TRUE
username: sa
password:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:53306/ody
username: root
password: 1234
flyway:
url: jdbc:mysql://localhost:53306/ody
user: root
password: 1234
connect-retries: 30
jpa:
hibernate:
ddl-auto: validate
dialect: org.hibernate.dialect.MySQLDialect
sql:
init:
mode: always

log:
file:
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ spring:
jdbc-url: jdbc:mysql://database-project.cluster-ro-cqsc6pyqhwww.ap-northeast-2.rds.amazonaws.com:3306/ody
username: ody
password: ENC(2n3gUzzFjknXpHDYwuF4d5BQw6XqLdsX)
flyway:
baseline-version: 2

log:
file:
Expand Down
1 change: 0 additions & 1 deletion backend/src/main/resources/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ springdoc:
odsay:
url: https://api.odsay.com/v1/api/searchPubTransPathT
api-key: ENC(4+ag02XbL8zS6rWoWHh7WzhKqBj5kaBwBcg04MpLr8nLJefO2PRY8E5o0WpRd3oRtvFv1s9lnWI=)
# TODO: 임시로 개인 api-key 추가 -> 팀 key로 변경 필요

google:
maps:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ALTER TABLE notification ADD CONSTRAINT notification_chk_1 CHECK (notification.type IN ('DEPARTURE_REMINDER', 'ENTRY', 'NUDGE', 'MEMBER_DELETION', 'ETA_NOTICE'));
ALTER TABLE notification DROP CONSTRAINT notification_chk_1;

ALTER TABLE notification ADD CONSTRAINT notification_chk_1 CHECK (`type` IN ('DEPARTURE_REMINDER', 'ENTRY', 'NUDGE', 'MEMBER_DELETION', 'ETA_NOTICE'));
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

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

[질문] drop 후 다시 add 해주는 이유가 궁금해요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

v1 스키마가 실행될 때 type에 대한 제약조건 notification_chk_1이 생성되는데
이 제약조건을 지우고 새로운 타입 체크가 추가된 notification_chk_1를 추가해주기 위해서 �drop을 추가했습니다 ~!

기존에 문제가 되지 않았던 이유는 dev, prod db에 접근해서 제약조건을 임의로 제거했기 때문이였어요

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! ALTER DATABASE ody CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; */
/*! ALTER TABLE member CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; */
/*! ALTER TABLE meeting CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; */
/*! ALTER TABLE mate CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; */
/*! ALTER TABLE notification CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; */
/*! ALTER TABLE eta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; */
ALTER DATABASE ody CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
ALTER TABLE member CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE meeting CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE mate CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE notification CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE eta CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*! ALTER TABLE member MODIFY COLUMN deleted_at timestamp(6); */
/*! ALTER TABLE meeting MODIFY COLUMN created_at timestamp(6); */
/*! ALTER TABLE meeting MODIFY COLUMN updated_at timestamp(6); */
/*! ALTER TABLE mate MODIFY COLUMN deleted_at timestamp(6); */
/*! ALTER TABLE eta CHANGE COLUMN created_at first_api_call_at timestamp not null; */
/*! ALTER TABLE eta CHANGE COLUMN updated_at last_api_call_at timestamp not null; */
/*! ALTER TABLE eta MODIFY COLUMN deleted_at timestamp(6); */
/*! ALTER TABLE notification MODIFY COLUMN send_at timestamp(6); */
/*! ALTER TABLE notification MODIFY COLUMN created_at timestamp(6); */
/*! ALTER TABLE notification MODIFY COLUMN updated_at timestamp(6); */
ALTER TABLE member MODIFY COLUMN deleted_at timestamp(6);
ALTER TABLE meeting MODIFY COLUMN created_at timestamp(6);
ALTER TABLE meeting MODIFY COLUMN updated_at timestamp(6);
ALTER TABLE mate MODIFY COLUMN deleted_at timestamp(6);
ALTER TABLE eta CHANGE COLUMN created_at first_api_call_at timestamp not null;
ALTER TABLE eta CHANGE COLUMN updated_at last_api_call_at timestamp not null;
ALTER TABLE eta MODIFY COLUMN deleted_at timestamp(6);
ALTER TABLE notification MODIFY COLUMN send_at timestamp(6);
ALTER TABLE notification MODIFY COLUMN created_at timestamp(6);
ALTER TABLE notification MODIFY COLUMN updated_at timestamp(6);
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.springframework.test.context.ActiveProfiles;

@Import({JpaAuditingConfig.class, FixtureGeneratorConfig.class, TestAuthConfig.class})
@ActiveProfiles("test")
@DataJpaTest
@ActiveProfiles("test")
public abstract class BaseRepositoryTest {

@Autowired
Expand Down
Loading