From 2da739f5efb18e2eeb8f1621174076750906a4a1 Mon Sep 17 00:00:00 2001 From: aesperer Date: Fri, 10 Nov 2023 09:37:25 +0900 Subject: [PATCH 1/4] =?UTF-8?q?create=20::=20custom=20club=20repository,?= =?UTF-8?q?=20fetchOne=EC=9D=84=20=ED=86=B5=ED=95=9C=20exist=20=EC=84=B1?= =?UTF-8?q?=EB=8A=A5=20=EC=B5=9C=EC=A0=81=ED=99=94=20=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/club/repository/ClubRepository.kt | 2 +- .../club/repository/CustomClubRepository.kt | 5 +++++ .../repository/CustomClubRepositoryImpl.kt | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepository.kt create mode 100644 bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepositoryImpl.kt diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/ClubRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/ClubRepository.kt index e156d461a..5b326ba73 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/ClubRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/ClubRepository.kt @@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.Query import team.msg.domain.club.model.Club import team.msg.domain.school.model.School -interface ClubRepository : JpaRepository { +interface ClubRepository : JpaRepository, CustomClubRepository { @EntityGraph(attributePaths = ["school"], type = EntityGraph.EntityGraphType.FETCH) fun findByNameAndSchool(name: String, school: School): Club? diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepository.kt new file mode 100644 index 000000000..b98172149 --- /dev/null +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepository.kt @@ -0,0 +1,5 @@ +package team.msg.domain.club.repository + +interface CustomClubRepository { + fun existsOne(id: Long): Boolean +} \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepositoryImpl.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepositoryImpl.kt new file mode 100644 index 000000000..7d84dc6ce --- /dev/null +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/club/repository/CustomClubRepositoryImpl.kt @@ -0,0 +1,18 @@ +package team.msg.domain.club.repository + +import com.querydsl.jpa.impl.JPAQueryFactory +import team.msg.domain.club.model.QClub.club + +class CustomClubRepositoryImpl( + private val queryFactory: JPAQueryFactory +) : CustomClubRepository { + + override fun existsOne(id: Long): Boolean { + val fetchOne = queryFactory.selectOne() + .from(club) + .where(club.id.eq(id)) + .fetchFirst() // limit 1 + + return fetchOne != null + } +} \ No newline at end of file From 5e23eb704b8c9bebbf34a95c2a134ae23e1ead2f Mon Sep 17 00:00:00 2001 From: aesperer Date: Fri, 10 Nov 2023 09:38:54 +0900 Subject: [PATCH 2/4] create :: custom school repository, fetchOne --- .../repository/CustomSchoolRepository.kt | 5 +++++ .../repository/CustomSchoolRepositoryImpl.kt | 18 ++++++++++++++++++ .../school/repository/SchoolRepository.kt | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepository.kt create mode 100644 bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepositoryImpl.kt diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepository.kt new file mode 100644 index 000000000..be4473c85 --- /dev/null +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepository.kt @@ -0,0 +1,5 @@ +package team.msg.domain.school.repository + +interface CustomSchoolRepository { + fun existsOne(id: Long): Boolean +} \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepositoryImpl.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepositoryImpl.kt new file mode 100644 index 000000000..87faf71c1 --- /dev/null +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/CustomSchoolRepositoryImpl.kt @@ -0,0 +1,18 @@ +package team.msg.domain.school.repository + +import com.querydsl.jpa.impl.JPAQueryFactory +import team.msg.domain.school.model.QSchool.school + +class CustomSchoolRepositoryImpl( + private val queryFactory: JPAQueryFactory +) : CustomSchoolRepository { + + override fun existsOne(id: Long): Boolean { + val fetchOne = queryFactory.selectOne() + .from(school) + .where(school.id.eq(id)) + .fetchFirst() // limit 1 + + return fetchOne != null + } +} \ No newline at end of file diff --git a/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/SchoolRepository.kt b/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/SchoolRepository.kt index 11f2c5e4d..f2b41d41c 100644 --- a/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/SchoolRepository.kt +++ b/bitgouel-domain/src/main/kotlin/team/msg/domain/school/repository/SchoolRepository.kt @@ -4,6 +4,6 @@ import org.springframework.data.repository.CrudRepository import team.msg.domain.school.enums.HighSchool import team.msg.domain.school.model.School -interface SchoolRepository : CrudRepository { +interface SchoolRepository : CrudRepository, CustomSchoolRepository { fun findByHighSchool(highSchool: HighSchool): School? } \ No newline at end of file From 74213e514abc0e4eae974c0d43e857d013fa06fc Mon Sep 17 00:00:00 2001 From: aesperer Date: Fri, 10 Nov 2023 09:41:09 +0900 Subject: [PATCH 3/4] =?UTF-8?q?update=20::=20data=20initializer=20count=20?= =?UTF-8?q?=EC=84=B1=EB=8A=A5=20=EA=B0=9C=EC=84=A0=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/kotlin/team/msg/common/init/DataInitializer.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bitgouel-api/src/main/kotlin/team/msg/common/init/DataInitializer.kt b/bitgouel-api/src/main/kotlin/team/msg/common/init/DataInitializer.kt index a006f3e1f..6452c64e5 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/common/init/DataInitializer.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/common/init/DataInitializer.kt @@ -41,17 +41,17 @@ class DataInitializer( /** * ApplicationReadyEvent가 발행되면 initData가 실행됩니다. - * school, club의 데이터 count가 0이라면 데이터 삽입이 실행됩니다. + * school, club id = 1인 엔티티가 존재하면 Data Init을 실행하지 않는다. */ @EventListener(ApplicationReadyEvent::class) @Transactional fun initData() { - if(schoolRepository.count() == 0L) { + if(schoolRepository.existsOne(1)) { log.info("=== RUN Init School Data ===") initSchool() } - if(clubRepository.count() == 0L) { + if(clubRepository.existsOne(1)) { log.info("=== RUN Init Club Data ===") initClub() } From 0bd513566cea2b79d0bf55839e7f1e0d01fc6f57 Mon Sep 17 00:00:00 2001 From: aesperer Date: Fri, 10 Nov 2023 10:07:46 +0900 Subject: [PATCH 4/4] =?UTF-8?q?update=20::=20deploy=20script=20log=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 8458bc2c3..403663c77 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,18 +1,18 @@ #!/bin/bash BUILD_JAR=$(ls /home/ec2-user/Bitgouel-Server/bitgouel-api/build/libs/*.jar) JAR_NAME=$(basename $BUILD_JAR) -echo "> build 파일명: $JAR_NAME" >> /home/ec2-user/action/deploy.log +echo "> build 파일명: $JAR_NAME" >> /home/ec2-user/deploy.log -echo "> build 파일 복사" >> /home/ec2-user/action/deploy.log -DEPLOY_PATH=/home/ec2-user/action/ +echo "> build 파일 복사" >> /home/ec2-user/deploy.log +DEPLOY_PATH=/home/ec2-user/ cp $BUILD_JAR $DEPLOY_PATH -echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/action/deploy.log +echo "> 현재 실행중인 애플리케이션 pid 확인" >> /home/ec2-user/deploy.log CURRENT_PID=$(pgrep -f $JAR_NAME) if [ -z $CURRENT_PID ] then - echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/action/deploy.log + echo "> 현재 구동중인 애플리케이션이 없으므로 종료하지 않습니다." >> /home/ec2-user/deploy.log else echo "> kill -15 $CURRENT_PID" kill -15 $CURRENT_PID @@ -20,5 +20,5 @@ else fi DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME -echo "> DEPLOY_JAR 배포" >> /home/ec2-user/action/deploy.log +echo "> DEPLOY_JAR 배포" >> /home/ec2-user/deploy.log nohup java -jar $DEPLOY_JAR --logging.file.path=/home/ec2-user/ --logging.level.org.hibernate.SQL=DEBUG >> /home/ec2-user/deploy.log 2>/home/ec2-user/deploy_err.log & \ No newline at end of file