[#7] feat: flyway migration 적용

- seed 적용
- 기존 DDL 내용 수정(update 관련 칼럼 추가)
This commit is contained in:
beaniejoy
2022-07-05 01:06:37 +09:00
parent 70816bbfc1
commit 9204bd48c5
11 changed files with 85 additions and 3 deletions

View File

@@ -17,7 +17,7 @@ class CafeController(
) {
@GetMapping
fun searchCafeList(
@PageableDefault(sort = ["name"], direction = Sort.Direction.ASC, size = 10) pageable: Pageable
@PageableDefault(sort = ["name"], direction = Sort.Direction.ASC, page = 0, size = 10) pageable: Pageable
): Page<CafeSearchResponseDto> {
return cafeService.getCafeList(pageable)
}

View File

@@ -2,8 +2,10 @@ package io.beaniejoy.dongnecafe.domain.cafe.service
import io.beaniejoy.dongnecafe.domain.cafe.dto.cafe.CafeInfoResponseDto
import io.beaniejoy.dongnecafe.domain.cafe.dto.cafe.CafeSearchResponseDto
import io.beaniejoy.dongnecafe.domain.cafe.entity.Cafe
import io.beaniejoy.dongnecafe.domain.cafe.error.CafeNotFoundException
import io.beaniejoy.dongnecafe.domain.cafe.repository.CafeRepository
import mu.KLogging
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.repository.findByIdOrNull
@@ -15,12 +17,13 @@ import org.springframework.transaction.annotation.Transactional
class CafeService(
private val cafeRepository: CafeRepository
) {
companion object: KLogging()
@Transactional(readOnly = true)
fun getCafeList(pageable: Pageable): Page<CafeSearchResponseDto> {
val cafeListWithPagination = cafeRepository.findAll(pageable)
val cafeList: Page<Cafe> = cafeRepository.findAll(pageable)
return cafeListWithPagination.map { CafeSearchResponseDto.of(it) }
return cafeList.map { CafeSearchResponseDto.of(it) }
}
@Transactional(readOnly = true)

View File

@@ -14,4 +14,5 @@ spring:
show-sql: true
flyway:
baseline-on-migrate: true
locations: classpath:db/migration,classpath:db/seed
# baseline-version: 0

View File

@@ -1,3 +1,5 @@
DROP TABLE IF EXISTS `cafe`;
CREATE TABLE `cafe` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '카페 ID',
`name` varchar(20) NOT NULL COMMENT '카페명',

View File

@@ -1,3 +1,5 @@
DROP TABLE IF EXISTS `cafe_menu`;
CREATE TABLE `cafe_menu` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '카페 메뉴 ID',
`name` varchar(50) NOT NULL COMMENT '카페 메뉴명',

View File

@@ -1,3 +1,5 @@
DROP TABLE IF EXISTS `cafe_image`;
CREATE TABLE `cafe_image` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '카페 이미지 ID',
`img_url` varchar(255) NOT NULL COMMENT '이미지 경로',

View File

@@ -1,3 +1,5 @@
DROP TABLE IF EXISTS `menu_option`;
CREATE TABLE `menu_option`(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '옵션 ID',
`title` varchar(50) NOT NULL COMMENT '메뉴 옵션 이름',

View File

@@ -1,3 +1,5 @@
DROP TABLE IF EXISTS `option_detail`;
CREATE TABLE `option_detail` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '옵션 상세 ID',
`name` varchar(50) NOT NULL COMMENT '옵션 상세명',

View File

@@ -0,0 +1,20 @@
INSERT IGNORE INTO `cafe` (name, address, phone_number, total_rate, description, created_at, created_by, updated_at, updated_by)
VALUES ('비니카페', '서울시 동대문구 전농로', '01011112222', 3.98, '언제나 상쾌한 비니카페', now(), 'system', null, null);
INSERT IGNORE INTO `cafe` (name, address, phone_number, total_rate, description, created_at, created_by, updated_at, updated_by)
VALUES ('조이카페', '서울시 영등포구', '01033334444', 4.67, '언제나 상쾌한 조이카페', now(), 'system', null, null);
INSERT IGNORE INTO `cafe` (name, address, phone_number, total_rate, description, created_at, created_by, updated_at, updated_by)
VALUES ('abc카페', '서울시 서대문구', '01025341432', 4.89, '언제나 상쾌한 abc카페', now(), 'system', null, null);
INSERT IGNORE INTO `cafe` (name, address, phone_number, total_rate, description, created_at, created_by, updated_at, updated_by)
VALUES ('동네주변카페', '서울시 송파구', '01022223333', 4.23, '언제나 상쾌한 동네주변카페', now(), 'system', null, null);
INSERT IGNORE INTO `cafe` (name, address, phone_number, total_rate, description, created_at, created_by, updated_at, updated_by)
VALUES ('방긋카페', '서울시 광진구', '01099998888', 4.35, '언제나 상쾌한 방긋카페', now(), 'system', null, null);
INSERT IGNORE INTO `cafe` (name, address, phone_number, total_rate, description, created_at, created_by, updated_at, updated_by)
VALUES ('example cafe1', '서울시 종로구', '01077779999', 2.85, '언제나 상쾌한 example cafe1', now(), 'system', null, null);
INSERT IGNORE INTO `cafe` (name, address, phone_number, total_rate, description, created_at, created_by, updated_at, updated_by)
VALUES ('example cafe2', '서울시', '01044445555', 3.12, '언제나 상쾌한 example cafe2', now(), 'system', null, null);

View File

@@ -0,0 +1,26 @@
DROP PROCEDURE IF EXISTS insertCafeImages;
DELIMITER $$
CREATE PROCEDURE insertCafeImages()
BEGIN
DECLARE i INT DEFAULT 0;
DECLARE j INT;
DECLARE idx_img INT DEFAULT 1;
DECLARE var_cafe_id binary(16);
DECLARE count_cafe INT;
SET count_cafe = (SELECT COUNT(*) FROM `cafe`);
WHILE(i <= count_cafe) DO
SET j = 1;
SET var_cafe_id = (SELECT id FROM `cafe` LIMIT i, 1);
WHILE(j <= 3) DO
INSERT IGNORE INTO `cafe_image` (img_url, created_at, created_by, updated_at, updated_by, cafe_id)
VALUES (CONCAT('test_img_url_', idx_img), now(), 'system', null, null, var_cafe_id);
SET j = j + 1;
SET idx_img = idx_img + 1;
END WHILE;
SET i = i + 1;
END WHILE;
END$$
DELIMITER ;
CALL insertCafeImages();

View File

@@ -0,0 +1,22 @@
DROP PROCEDURE IF EXISTS insertCafeMenus;
DELIMITER $$
CREATE PROCEDURE insertCafeMenus()
BEGIN
DECLARE i INT DEFAULT 0;
DECLARE j INT;
DECLARE var_cafe_id binary(16);
WHILE(i <= 4) DO
SET j = 1;
SET var_cafe_id = (SELECT id FROM `cafe` LIMIT i, 1);
WHILE(j <= 10) DO
INSERT IGNORE INTO `cafe_menu` (name, price, created_at, created_by, updated_at, updated_by, cafe_id)
VALUES (CONCAT('커피', j), FLOOR(RAND() * 10 + 1) * 1000, now(), 'system', null, null, var_cafe_id);
SET j = j + 1;
END WHILE;
SET i = i + 1;
END WHILE;
END$$
DELIMITER ;
CALL insertCafeMenus();