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

[refactor] : PostgreSQL -> MySQL 마이그레이션 #76

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 12 additions & 12 deletions api/src/test/java/dev/hooon/show/ShowSeatsApiControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ void getBookedSeatInfo_test() throws Exception {
status().isOk(),

jsonPath("$.seatsDetailInfos.size()").value(2),
jsonPath("$.seatsDetailInfos[0].id").exists(),
jsonPath("$.seatsDetailInfos[0].date").value("2024-01-01"),
jsonPath("$.seatsDetailInfos[0].isSeat").value(true),
jsonPath("$.seatsDetailInfos[0].positionInfo_sector").value("1층"),
jsonPath("$.seatsDetailInfos[0].positionInfo_row").value("A"),
jsonPath("$.seatsDetailInfos[0].positionInfo_col").value("7"),
jsonPath("$.seatsDetailInfos[0].price").value(70000),
jsonPath("$.seatsDetailInfos[0].status").value(SeatStatus.BOOKED.name()),

jsonPath("$.seatsDetailInfos[1].id").exists(),
jsonPath("$.seatsDetailInfos[1].date").value("2024-01-01"),
jsonPath("$.seatsDetailInfos[1].isSeat").value(true),
jsonPath("$.seatsDetailInfos[1].positionInfo_sector").value("1층"),
jsonPath("$.seatsDetailInfos[1].positionInfo_row").value("A"),
jsonPath("$.seatsDetailInfos[1].positionInfo_col").value("8"),
jsonPath("$.seatsDetailInfos[1].price").value(50000),
jsonPath("$.seatsDetailInfos[1].status").value(SeatStatus.BOOKED.name())
jsonPath("$.seatsDetailInfos[1].positionInfo_col").value("7"),
jsonPath("$.seatsDetailInfos[1].price").value(70000),
jsonPath("$.seatsDetailInfos[1].status").value(SeatStatus.BOOKED.name()),

jsonPath("$.seatsDetailInfos[0].id").exists(),
jsonPath("$.seatsDetailInfos[0].date").value("2024-01-01"),
jsonPath("$.seatsDetailInfos[0].isSeat").value(true),
jsonPath("$.seatsDetailInfos[0].positionInfo_sector").value("1층"),
jsonPath("$.seatsDetailInfos[0].positionInfo_row").value("A"),
jsonPath("$.seatsDetailInfos[0].positionInfo_col").value("8"),
jsonPath("$.seatsDetailInfos[0].price").value(50000),
jsonPath("$.seatsDetailInfos[0].status").value(SeatStatus.BOOKED.name())
);
}
}
1 change: 0 additions & 1 deletion api/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ spring:
ddl-auto: create
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true

logging:
Expand Down
13 changes: 7 additions & 6 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
dependencies {
runtimeOnly 'org.postgresql:postgresql'
runtimeOnly 'com.mysql:mysql-connector-j'
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
//테스트 픽쳐에서 사용할 의존성
testFixturesImplementation 'org.springframework.boot:spring-boot-starter-test'
testFixturesImplementation "org.testcontainers:testcontainers:1.19.3"
testFixturesImplementation "org.testcontainers:postgresql:1.19.3"
testFixturesImplementation 'org.springframework:spring-tx:6.1.1'
// 패스워드 암호화
implementation group: 'org.mindrot', name: 'jbcrypt', version: '0.3m'
// JWT
Expand All @@ -18,6 +13,12 @@ dependencies {
// 레디스 LocalDateTime 역직렬화
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
implementation 'com.fasterxml.jackson.core:jackson-databind'

//테스트 픽쳐에서 사용할 의존성
testFixturesImplementation 'org.springframework.boot:spring-boot-starter-test'
testFixturesImplementation "org.testcontainers:testcontainers:1.19.3"
testFixturesImplementation "org.testcontainers:mysql:1.19.3"
testFixturesImplementation 'org.springframework:spring-tx:6.1.1'
}

bootJar { enabled = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public interface SeatJpaRepository extends JpaRepository<Seat, Long> {
select
new dev.hooon.show.dto.query.seats.SeatsInfoDto(seat.seatGrade, COUNT(seat), seat.price)
from Seat seat
join seat.show show
where show.id= :showId and seat.showDate= :date and seat.showRound.round= :round
where seat.show.id= :showId and seat.showDate= :date and seat.showRound.round= :round
group by seat.seatGrade, seat.price
""")
List<SeatsInfoDto> findSeatInfoByShowIdAndDateAndRound(
Expand All @@ -58,6 +57,7 @@ List<SeatsInfoDto> findSeatInfoByShowIdAndDateAndRound(
new dev.hooon.show.dto.query.seats.SeatsDetailDto(seat.id, seat.showDate, seat.isSeat, seat.positionInfo.sector, seat.positionInfo.row, seat.positionInfo.col, seat.price, seat.seatStatus)
from Seat seat
where seat.show.id = :showId and seat.showDate = :date and seat.showRound.round = :round and seat.seatGrade = :grade
order by seat.id desc
""")
List<SeatsDetailDto> findSeatsByShowIdAndDateAndRoundAndGrade(
@Param("showId") Long showId,
Expand All @@ -77,6 +77,7 @@ List<SeatsDetailDto> findSeatsByShowIdAndDateAndRoundAndGrade(
and s.seatStatus = :status
and s.showDate = :date
and s.showRound.round = :round
order by s.id desc
""")
List<SeatsDetailDto> findSeatsDetailByStatusAndDateAndRound(
@Param("showId") Long showId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ s.name, p.name, s.showPeriod.startDate, s.showPeriod.endDate, sum(b.ticketCount)
inner join Booking b on s.id = b.show.id
where s.category = :category
and b.createdAt between :startAt and :endAt
group by s.id, s.name, p.name, s.showPeriod.startDate, s.showPeriod.endDate
group by s.id
order by sum(b.ticketCount) desc
""")
List<ShowStatisticDto> findBookingStatisticByCategoryAndPeriod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static dev.hooon.waitingbooking.exception.WaitingBookingErrorCode.*;
import static jakarta.persistence.CascadeType.*;
import static jakarta.persistence.ConstraintMode.*;
import static jakarta.persistence.EnumType.*;
import static jakarta.persistence.FetchType.*;
import static jakarta.persistence.GenerationType.*;

Expand All @@ -20,6 +21,7 @@
import dev.hooon.waitingbooking.domain.entity.waitingbookingseat.SelectedSeat;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -43,6 +45,7 @@ public class WaitingBooking extends TimeBaseEntity {
@Column(name = "waiting_booking_id")
private Long id;

@Enumerated(STRING)
@Column(name = "waiting_booking_status", nullable = false)
private WaitingStatus status;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.*;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.DisplayName;
Expand Down Expand Up @@ -88,6 +89,7 @@ void findSeatsByShowIdAndDateAndRoundAndGradeTest() {
round,
VIP
);
Collections.reverse(seatsDetailDtoList);

// then
assertAll(
Expand Down
1 change: 0 additions & 1 deletion core/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ spring:
ddl-auto: create
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true

logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.utility.DockerImageName;

public abstract class TestContainerSupport {
Expand All @@ -12,34 +13,34 @@ protected TestContainerSupport() {
}

private static final String REDIS_IMAGE = "redis:latest";
private static final String POSTGRES_IMAGE = "postgres:13-alpine";
private static final String MYSQL_IMAGE = "mysql:8.0";
private static final int REDIS_PORT = 6379;

private static final int POSTGRES_PORT = 5432;
private static final int MYSQL_PORT = 3306;
private static final GenericContainer<?> REDIS;

private static final PostgreSQLContainer<?> POSTGRES;
private static final JdbcDatabaseContainer<?> MYSQL;

static {
REDIS = new GenericContainer<>(DockerImageName.parse(REDIS_IMAGE))
.withExposedPorts(REDIS_PORT)
.withReuse(true);
POSTGRES = new PostgreSQLContainer<>(DockerImageName.parse(POSTGRES_IMAGE))
.withExposedPorts(POSTGRES_PORT)
MYSQL = new MySQLContainer<>(DockerImageName.parse(MYSQL_IMAGE))
.withExposedPorts(MYSQL_PORT)
.withReuse(true);

REDIS.start();
POSTGRES.start();
MYSQL.start();
}

@DynamicPropertySource
public static void overrideProps(DynamicPropertyRegistry registry){
registry.add("spring.data.redis.host", REDIS::getHost);
registry.add("spring.data.redis.port", () -> String.valueOf(REDIS.getMappedPort(REDIS_PORT)));

registry.add("spring.datasource.driver-class-name", POSTGRES::getDriverClassName);
registry.add("spring.datasource.url", POSTGRES::getJdbcUrl);
registry.add("spring.datasource.username", POSTGRES::getUsername);
registry.add("spring.datasource.password", POSTGRES::getPassword);
registry.add("spring.datasource.driver-class-name", MYSQL::getDriverClassName);
registry.add("spring.datasource.url", MYSQL::getJdbcUrl);
registry.add("spring.datasource.username", MYSQL::getUsername);
registry.add("spring.datasource.password", MYSQL::getPassword);
}
}
11 changes: 4 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ services:
platform: linux/amd64

db-master:
image: postgres:13-alpine
image: mysql:8.0
container_name: master_db
environment:
POSTGRES_USER: ${MASTER_USER}
POSTGRES_PASSWORD: ${MASTER_PASSWORD}
POSTGRES_DB: master_db
MYSQL_DATABASE: master_db
MYSQL_ROOT_PASSWORD: ${MASTER_PASSWORD}
ports:
- "5432:5432"
volumes:
- postgresql_data:/var/lib/postgresql/data
- "3306:3306"

redis:
image: redis:latest
Expand Down
1 change: 0 additions & 1 deletion scheduler/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ spring:
ddl-auto: create
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
format_sql: true

mail:
Expand Down