From b76824ce6fce6a69f23346d6a7764eebff0ff1b5 Mon Sep 17 00:00:00 2001 From: beaniejoy Date: Fri, 1 Jul 2022 15:26:42 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[#7]=20flyway=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - flyway DDL sql 파일 추가(진행중) - flyway 기본 세팅 --- build.gradle | 3 +++ src/main/resources/application.yml | 3 +++ .../resources/db/migration/V001__Create_cafe.sql | 13 +++++++++++++ .../db/migration/V002__Create_cafe_menu.sql | 11 +++++++++++ .../db/migration/V003__Create_cafe_image.sql | 10 ++++++++++ .../db/migration/V004__Create_menu_option.sql | 10 ++++++++++ .../db/migration/V005__Create_option_detail.sql | 11 +++++++++++ .../resources/db/migration/V006__Create_user.sql | 11 +++++++++++ .../db/migration/V007__Create_review.sql | 15 +++++++++++++++ .../resources/db/migration/V008__Create_cart.sql | 13 +++++++++++++ .../db/migration/V009__Create_basket.sql | 12 ++++++++++++ .../db/migration/V010__Create_basket_option.sql | 11 +++++++++++ .../db/migration/V011__Create_menu_order.sql | 14 ++++++++++++++ 13 files changed, 137 insertions(+) create mode 100644 src/main/resources/db/migration/V001__Create_cafe.sql create mode 100644 src/main/resources/db/migration/V002__Create_cafe_menu.sql create mode 100644 src/main/resources/db/migration/V003__Create_cafe_image.sql create mode 100644 src/main/resources/db/migration/V004__Create_menu_option.sql create mode 100644 src/main/resources/db/migration/V005__Create_option_detail.sql create mode 100644 src/main/resources/db/migration/V006__Create_user.sql create mode 100644 src/main/resources/db/migration/V007__Create_review.sql create mode 100644 src/main/resources/db/migration/V008__Create_cart.sql create mode 100644 src/main/resources/db/migration/V009__Create_basket.sql create mode 100644 src/main/resources/db/migration/V010__Create_basket_option.sql create mode 100644 src/main/resources/db/migration/V011__Create_menu_order.sql diff --git a/build.gradle b/build.gradle index 65520a1..73e8acb 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ buildscript { springBootVersion = '2.7.0' dependencyManagementVersion = '1.0.11.RELEASE' kotlinVersion = '1.6.21' + flywayVersion = '8.5.11' } repositories { mavenCentral() @@ -60,6 +61,8 @@ dependencies { runtimeOnly 'mysql:mysql-connector-java' // MySQL runtimeOnly 'com.h2database:h2' // H2 + implementation "org.flywaydb:flyway-core:${flywayVersion}" // flyway + testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3482f2e..17804e4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,3 +9,6 @@ spring: dialect: org.hibernate.dialect.MySQL5InnoDBDialect format_sql: true show-sql: true + flyway: + baseline-on-migrate: true +# baseline-version: 0 diff --git a/src/main/resources/db/migration/V001__Create_cafe.sql b/src/main/resources/db/migration/V001__Create_cafe.sql new file mode 100644 index 0000000..ca52ad6 --- /dev/null +++ b/src/main/resources/db/migration/V001__Create_cafe.sql @@ -0,0 +1,13 @@ +CREATE TABLE `cafe` ( + `cafe_id` binary(16) NOT NULL COMMENT '카페식별번호', + `name` varchar(20) NOT NULL COMMENT '카페명', + `address` varchar(100) NOT NULL COMMENT '카페 주소', + `phone_number` varchar(11) NOT NULL COMMENT '카페 전화번호', + `total_rate` float NOT NULL COMMENT '카페 종합 평가 점수', + `description` varchar(255) COMMENT '카페 상세설명', + `created_at` datetime NOT NULL COMMENT '카페 등록날짜', + `created_by` varchar(10) NOT NULL COMMENT '카페 등록자', + `updated_at` datetime COMMENT '카페 변경날짜', + `updated_by` varchar(10) NOT NULL COMMENT '카페 변경자', + PRIMARY KEY (`cafe_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V002__Create_cafe_menu.sql b/src/main/resources/db/migration/V002__Create_cafe_menu.sql new file mode 100644 index 0000000..26ca8b0 --- /dev/null +++ b/src/main/resources/db/migration/V002__Create_cafe_menu.sql @@ -0,0 +1,11 @@ +CREATE TABLE `cafe_menu` ( + `menu_id` binary(16) NOT NULL COMMENT '카페 메뉴 식별번호', + `name` varchar(50) NOT NULL COMMENT '카페 메뉴명', + `price` int NOT NULL COMMENT '메뉴 가격', + `created_date` datetime NOT NULL COMMENT '메뉴 등록날짜', + `updated_date` datetime COMMENT '메뉴 수정날짜', + `cafe_id` binary(16) NOT NULL COMMENT '연관된 카페식별번호', + PRIMARY KEY (`menu_id`), + KEY `cafe_id` (`cafe_id`), + FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`cafe_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V003__Create_cafe_image.sql b/src/main/resources/db/migration/V003__Create_cafe_image.sql new file mode 100644 index 0000000..953db04 --- /dev/null +++ b/src/main/resources/db/migration/V003__Create_cafe_image.sql @@ -0,0 +1,10 @@ +CREATE TABLE `cafe_image` ( + `cafe_img_id` binary(16) NOT NULL COMMENT '카페 이미지 식별번호', + `img_url` varchar(255) NOT NULL COMMENT '이미지 경로', + `created_date` datetime NOT NULL COMMENT '이미지 등록날짜', + `updated_date` datetime COMMENT '이미지 수정날짜', + `cafe_id` binary(16) NOT NULL COMMENT '연관된 카페식별번호', + PRIMARY KEY (`cafe_img_id`), + KEY `cafe_id` (`cafe_id`), + FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`cafe_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V004__Create_menu_option.sql b/src/main/resources/db/migration/V004__Create_menu_option.sql new file mode 100644 index 0000000..2ae7088 --- /dev/null +++ b/src/main/resources/db/migration/V004__Create_menu_option.sql @@ -0,0 +1,10 @@ +CREATE TABLE `menu_option`( + `option_id` binary(16) NOT NULL COMMENT '옵션 식별번호', + `title`varchar(50) NOT NULL COMMENT '메뉴 옵션 이름', + `created_date` datetime NOT NULL COMMENT '옵션 등록날짜', + `updated_date` datetime COMMENT '옵션 수정날짜', + `menu_id` binary(16) NOT NULL COMMENT '연관된 카페 메뉴 식별번호', + PRIMARY KEY (`option_id`), + KEY `menu_id` (`menu_id`), + FOREIGN KEY (`menu_id`) REFERENCES `cafe_menu` (`menu_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V005__Create_option_detail.sql b/src/main/resources/db/migration/V005__Create_option_detail.sql new file mode 100644 index 0000000..3e7a577 --- /dev/null +++ b/src/main/resources/db/migration/V005__Create_option_detail.sql @@ -0,0 +1,11 @@ +CREATE TABLE `option_detail` ( + `option_detail_id` bigint NOT NULL COMMENT '옵션 상세 번호', + `name` varchar(50) NOT NULL COMMENT '옵션 상세명', + `extra` int NOT NULL COMMENT '옵션 추가 요금', + `created_date` datetime NOT NULL COMMENT '옵션 상세 등록날짜', + `updated_date` datetime COMMENT '옵션 상세 수정날짜', + `option_id` binary(16) NOT NULL COMMENT '연관된 옵션 식별번호', + PRIMARY KEY (`option_detail_id`), + KEY `option_id` (`option_id`), + FOREIGN KEY (`option_id`) REFERENCES `menu_option` (`option_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V006__Create_user.sql b/src/main/resources/db/migration/V006__Create_user.sql new file mode 100644 index 0000000..c90b186 --- /dev/null +++ b/src/main/resources/db/migration/V006__Create_user.sql @@ -0,0 +1,11 @@ +CREATE TABLE `user` ( + `user_id` binary(16) NOT NULL COMMENT '사용자 식별번호', + `email`varchar(50) NOT NULL COMMENT '사용자 이메일', + `password` varchar(100) NOT NULL COMMENT '계정 비밀번호', + `address` varchar(100) NOT NULL COMMENT '사용자 주소', + `phone_number` varchar(11) NOT NULL COMMENT '사용자 전화번호', + `role` varchar(20) NOT NULL COMMENT '사용자 권한', + `created_date` datetime NOT NULL COMMENT '사용자 등록날짜', + `updated_date` datetime COMMENT '사용자 수정날짜', + PRIMARY KEY (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V007__Create_review.sql b/src/main/resources/db/migration/V007__Create_review.sql new file mode 100644 index 0000000..b68f6d3 --- /dev/null +++ b/src/main/resources/db/migration/V007__Create_review.sql @@ -0,0 +1,15 @@ +CREATE TABLE `review` ( + `review_id` binary(16) NOT NULL COMMENT '리뷰 식별번호', + `content`varchar(255) NOT NULL COMMENT '리뷰 내용', + `img_url` varchar(255) NOT NULL COMMENT '리뷰 첨부사진 주소', + `rate` tinyint NOT NULL COMMENT '평가점수(0 ~ 5점)', + `created_date` datetime NOT NULL COMMENT '리뷰 등록날짜', + `updated_date` datetime COMMENT '리뷰 수정날짜', + `user_id` binary(16) NOT NULL COMMENT '리뷰 작성한 사용자 식별번호', + `cafe_id` binary(16) NOT NULL COMMENT '리뷰 대상 카페 식별번호', + PRIMARY KEY (`review_id`), + KEY `user_id` (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`), + KEY `cafe_id` (`cafe_id`), + FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`cafe_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V008__Create_cart.sql b/src/main/resources/db/migration/V008__Create_cart.sql new file mode 100644 index 0000000..65f2c46 --- /dev/null +++ b/src/main/resources/db/migration/V008__Create_cart.sql @@ -0,0 +1,13 @@ +CREATE TABLE `cart` ( + `cart_id` binary(16) NOT NULL COMMENT '장바구니 식별번호', + `cafe_name` varchar(20) NOT NULL COMMENT '장바구니에 담긴 카페 이름', + `check_ordered` tinyint NOT NULL COMMENT '장바구니의 주문 여부', + `total_price` int NOT NULL COMMENT '장바구니에 담긴 총 금액', + `created_date` datetime NOT NULL COMMENT '장바구니 등록날짜', + `updated_date` datetime COMMENT '장바구니 수정날짜', + `cafe_id` binary(16) NOT NULL COMMENT '장바구니에 담긴 카페 식별번호', + `user_id` binary(16) NOT NULL COMMENT '장바구니 주인 사용자 식별번호', + PRIMARY KEY (`cart_id`), + KEY `user_id` (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V009__Create_basket.sql b/src/main/resources/db/migration/V009__Create_basket.sql new file mode 100644 index 0000000..58e20e0 --- /dev/null +++ b/src/main/resources/db/migration/V009__Create_basket.sql @@ -0,0 +1,12 @@ +CREATE TABLE `basket` ( + `basket_id` binary(16) NOT NULL COMMENT '장바구니 품목 식별번호', + `menu_name` varchar(50) NOT NULL COMMENT '장바구니 품목 이름', + `menu_count` int NOT NULL COMMENT '장바구니 품목 개수', + `menu_price` int NOT NULL COMMENT '장바구니 품목 가격', + `created_date` datetime NOT NULL COMMENT '장바구니 품목 등록날짜', + `updated_date` datetime COMMENT '장바구니 품목 수정날짜', + `cart_id` binary(16) NOT NULL COMMENT '해당 품목이 담긴 장바구니 식별번호', + PRIMARY KEY (`basket_id`), + KEY `cart_id` (`cart_id`), + FOREIGN KEY (`cart_id`) REFERENCES `cart` (`cart_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V010__Create_basket_option.sql b/src/main/resources/db/migration/V010__Create_basket_option.sql new file mode 100644 index 0000000..3369b57 --- /dev/null +++ b/src/main/resources/db/migration/V010__Create_basket_option.sql @@ -0,0 +1,11 @@ +CREATE TABLE `basket_option` ( + `basket_option_id` binary(16) NOT NULL COMMENT '품목 추가옵션 식별번호', + `option_name`varchar(50) NOT NULL COMMENT '품목 추가옵션 내용', + `option_extra` int NOT NULL COMMENT '품목 추가옵션 추가요금', + `created_date` datetime NOT NULL COMMENT '품목 추가옵션 등록날짜', + `updated_date` datetime COMMENT '품목 추가옵션 수정날짜', + `basket_id` binary(16) NOT NULL COMMENT '추가옵션 대상 장바구니 품목 식별번호', + PRIMARY KEY (`basket_option_id`), + KEY `basket_id` (`basket_id`), + FOREIGN KEY (`basket_id`) REFERENCES `basket` (`basket_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V011__Create_menu_order.sql b/src/main/resources/db/migration/V011__Create_menu_order.sql new file mode 100644 index 0000000..ef18fc7 --- /dev/null +++ b/src/main/resources/db/migration/V011__Create_menu_order.sql @@ -0,0 +1,14 @@ +CREATE TABLE `menu_order` ( + `order_id` binary(16) NOT NULL COMMENT '주문 식별번호', + `order_status` varchar(20) NOT NULL COMMENT '주문 상태', + `request_message` varchar(255) NOT NULL COMMENT '주문 요청사항', + `created_date` datetime NOT NULL COMMENT '주문 등록날짜', + `updated_date` datetime COMMENT '주문 수정날짜', + `cart_id` binary(16) NOT NULL COMMENT '주문된 카트 식별번호', + `user_id` binary(16) NOT NULL COMMENT '주문한 사용자 식별번호', + PRIMARY KEY (`order_id`), + KEY `cart_id` (`cart_id`), + FOREIGN KEY (`cart_id`) REFERENCES `cart` (`cart_id`), + KEY `user_id` (`user_id`), + FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file From 70816bbfc1a7102b331ef4dbbe2dd9bbd9f48b1f Mon Sep 17 00:00:00 2001 From: beaniejoy Date: Fri, 1 Jul 2022 18:24:01 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[#7]=20feat:=20flyway=20=EA=B8=B0=EB=B3=B8?= =?UTF-8?q?=20=EC=84=B8=ED=8C=85=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - flyway 버전 다운(mysql 5.7 호환 이슈) - cafe 도메인 관련 table DDL 구성 (초기 세팅 DDL에서 수정) - BaseTimeEntity 내용 수정(createdBy, updatedBy 내용 추가) --- build.gradle | 3 ++- .../common/entity/BaseEntityAuditorAware.kt | 13 +++++++++++++ .../common/{domain => entity}/BaseTimeEntity.kt | 14 +++++++++++--- .../cafe/dto/menu/OptionDetailResponseDto.kt | 2 +- .../dongnecafe/domain/cafe/entity/Cafe.kt | 2 +- .../dongnecafe/domain/cafe/entity/CafeImage.kt | 2 +- .../dongnecafe/domain/cafe/entity/CafeMenu.kt | 2 +- .../dongnecafe/domain/cafe/entity/MenuOption.kt | 2 +- .../domain/cafe/entity/OptionDetail.kt | 9 ++++----- src/main/resources/application.yml | 7 +++++-- .../resources/db/migration/V001__Create_cafe.sql | 10 +++++----- .../db/migration/V002__Create_cafe_menu.sql | 16 +++++++++------- .../db/migration/V003__Create_cafe_image.sql | 14 ++++++++------ .../db/migration/V004__Create_menu_option.sql | 16 +++++++++------- .../db/migration/V005__Create_option_detail.sql | 16 +++++++++------- .../resources/db/migration/V006__Create_user.sql | 11 ----------- .../db/migration/V007__Create_review.sql | 15 --------------- .../resources/db/migration/V008__Create_cart.sql | 13 ------------- .../db/migration/V009__Create_basket.sql | 12 ------------ .../db/migration/V010__Create_basket_option.sql | 11 ----------- .../db/migration/V011__Create_menu_order.sql | 14 -------------- 21 files changed, 80 insertions(+), 124 deletions(-) create mode 100644 src/main/java/io/beaniejoy/dongnecafe/common/entity/BaseEntityAuditorAware.kt rename src/main/java/io/beaniejoy/dongnecafe/common/{domain => entity}/BaseTimeEntity.kt (59%) delete mode 100644 src/main/resources/db/migration/V006__Create_user.sql delete mode 100644 src/main/resources/db/migration/V007__Create_review.sql delete mode 100644 src/main/resources/db/migration/V008__Create_cart.sql delete mode 100644 src/main/resources/db/migration/V009__Create_basket.sql delete mode 100644 src/main/resources/db/migration/V010__Create_basket_option.sql delete mode 100644 src/main/resources/db/migration/V011__Create_menu_order.sql diff --git a/build.gradle b/build.gradle index 73e8acb..0352f7f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { springBootVersion = '2.7.0' dependencyManagementVersion = '1.0.11.RELEASE' kotlinVersion = '1.6.21' - flywayVersion = '8.5.11' + flywayVersion = '7.15.0' } repositories { mavenCentral() @@ -45,6 +45,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}") implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation('io.github.microutils:kotlin-logging:2.1.21') diff --git a/src/main/java/io/beaniejoy/dongnecafe/common/entity/BaseEntityAuditorAware.kt b/src/main/java/io/beaniejoy/dongnecafe/common/entity/BaseEntityAuditorAware.kt new file mode 100644 index 0000000..e253520 --- /dev/null +++ b/src/main/java/io/beaniejoy/dongnecafe/common/entity/BaseEntityAuditorAware.kt @@ -0,0 +1,13 @@ +package io.beaniejoy.dongnecafe.common.entity + +import org.springframework.data.domain.AuditorAware +import org.springframework.stereotype.Component +import java.util.* + +@Component +class BaseEntityAuditorAware: AuditorAware { + override fun getCurrentAuditor(): Optional { + // TODO 추후 사용자 로그인 기능 추가되면 실제 등록한 사용자를 DB에 저장하는 방향으로 수정 + return Optional.of("system") + } +} \ No newline at end of file diff --git a/src/main/java/io/beaniejoy/dongnecafe/common/domain/BaseTimeEntity.kt b/src/main/java/io/beaniejoy/dongnecafe/common/entity/BaseTimeEntity.kt similarity index 59% rename from src/main/java/io/beaniejoy/dongnecafe/common/domain/BaseTimeEntity.kt rename to src/main/java/io/beaniejoy/dongnecafe/common/entity/BaseTimeEntity.kt index 3bd74a6..633cad1 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/common/domain/BaseTimeEntity.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/common/entity/BaseTimeEntity.kt @@ -1,6 +1,8 @@ -package io.beaniejoy.dongnecafe.common.domain +package io.beaniejoy.dongnecafe.common.entity +import org.springframework.data.annotation.CreatedBy import org.springframework.data.annotation.CreatedDate +import org.springframework.data.annotation.LastModifiedBy import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.time.LocalDateTime @@ -9,10 +11,16 @@ import javax.persistence.MappedSuperclass @MappedSuperclass @EntityListeners(AuditingEntityListener::class) -open class BaseTimeEntity( +class BaseTimeEntity( @CreatedDate val createdAt: LocalDateTime = LocalDateTime.now(), + @CreatedBy + val createdBy: String = "", + @LastModifiedDate - val updatedAt: LocalDateTime? = null + val updatedAt: LocalDateTime? = null, + + @LastModifiedBy + val updatedBy: String? = null ) \ No newline at end of file diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/dto/menu/OptionDetailResponseDto.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/dto/menu/OptionDetailResponseDto.kt index 31c23bb..756db31 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/dto/menu/OptionDetailResponseDto.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/dto/menu/OptionDetailResponseDto.kt @@ -13,7 +13,7 @@ data class OptionDetailResponseDto( return OptionDetailResponseDto( id = optionDetail.id, name = optionDetail.name, - extra = optionDetail.extra + extra = optionDetail.extraPrice ) } } diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/Cafe.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/Cafe.kt index 9ae25e9..c5bd554 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/Cafe.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/Cafe.kt @@ -1,6 +1,6 @@ package io.beaniejoy.dongnecafe.domain.cafe.entity -import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity +import io.beaniejoy.dongnecafe.common.entity.BaseTimeEntity import javax.persistence.* @Entity diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeImage.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeImage.kt index ab6b32e..716ed5f 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeImage.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeImage.kt @@ -1,6 +1,6 @@ package io.beaniejoy.dongnecafe.domain.cafe.entity -import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity +import io.beaniejoy.dongnecafe.common.entity.BaseTimeEntity import javax.persistence.* @Entity diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeMenu.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeMenu.kt index bef74c4..b8f2872 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeMenu.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/CafeMenu.kt @@ -1,6 +1,6 @@ package io.beaniejoy.dongnecafe.domain.cafe.entity -import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity +import io.beaniejoy.dongnecafe.common.entity.BaseTimeEntity import java.math.BigDecimal import javax.persistence.* diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/MenuOption.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/MenuOption.kt index 266324b..65884ba 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/MenuOption.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/MenuOption.kt @@ -1,6 +1,6 @@ package io.beaniejoy.dongnecafe.domain.cafe.entity -import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity +import io.beaniejoy.dongnecafe.common.entity.BaseTimeEntity import javax.persistence.* @Entity diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/OptionDetail.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/OptionDetail.kt index 4a6955d..68b8bf1 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/OptionDetail.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/entity/OptionDetail.kt @@ -1,6 +1,6 @@ package io.beaniejoy.dongnecafe.domain.cafe.entity -import io.beaniejoy.dongnecafe.common.domain.BaseTimeEntity +import io.beaniejoy.dongnecafe.common.entity.BaseTimeEntity import java.math.BigDecimal import javax.persistence.* @@ -14,11 +14,10 @@ class OptionDetail( @Column(name = "name", nullable = false) val name: String, - @Column(name = "extra", nullable = false) - val extra: BigDecimal, + @Column(name = "extra_price", nullable = false) + val extraPrice: BigDecimal, @ManyToOne @JoinColumn(name = "option_id", nullable = false) val menuOption: MenuOption -): BaseTimeEntity() { -} \ No newline at end of file +): BaseTimeEntity() \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 17804e4..2252c8c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,9 +1,12 @@ spring: datasource: - url: jdbc:h2:mem:testdb;MODE=MySQL + url: jdbc:mysql://localhost:3306/dongne?autoreconnect=true&characterEncoding=utf8&serverTimezone=Asia/Seoul + username: root + password: beaniejoy # TODO 추후 보안에 대해 생각해보기 + driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: - ddl-auto: update + ddl-auto: none # flyway migration 사용 properties: hibernate: dialect: org.hibernate.dialect.MySQL5InnoDBDialect diff --git a/src/main/resources/db/migration/V001__Create_cafe.sql b/src/main/resources/db/migration/V001__Create_cafe.sql index ca52ad6..5941d25 100644 --- a/src/main/resources/db/migration/V001__Create_cafe.sql +++ b/src/main/resources/db/migration/V001__Create_cafe.sql @@ -1,13 +1,13 @@ CREATE TABLE `cafe` ( - `cafe_id` binary(16) NOT NULL COMMENT '카페식별번호', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '카페 ID', `name` varchar(20) NOT NULL COMMENT '카페명', `address` varchar(100) NOT NULL COMMENT '카페 주소', `phone_number` varchar(11) NOT NULL COMMENT '카페 전화번호', `total_rate` float NOT NULL COMMENT '카페 종합 평가 점수', `description` varchar(255) COMMENT '카페 상세설명', `created_at` datetime NOT NULL COMMENT '카페 등록날짜', - `created_by` varchar(10) NOT NULL COMMENT '카페 등록자', - `updated_at` datetime COMMENT '카페 변경날짜', - `updated_by` varchar(10) NOT NULL COMMENT '카페 변경자', - PRIMARY KEY (`cafe_id`) + `created_by` varchar(20) NOT NULL COMMENT '카페 등록자', + `updated_at` datetime NULL COMMENT '카페 변경날짜', + `updated_by` varchar(20) NULL COMMENT '카페 변경자', + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V002__Create_cafe_menu.sql b/src/main/resources/db/migration/V002__Create_cafe_menu.sql index 26ca8b0..40d197b 100644 --- a/src/main/resources/db/migration/V002__Create_cafe_menu.sql +++ b/src/main/resources/db/migration/V002__Create_cafe_menu.sql @@ -1,11 +1,13 @@ CREATE TABLE `cafe_menu` ( - `menu_id` binary(16) NOT NULL COMMENT '카페 메뉴 식별번호', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '카페 메뉴 ID', `name` varchar(50) NOT NULL COMMENT '카페 메뉴명', - `price` int NOT NULL COMMENT '메뉴 가격', - `created_date` datetime NOT NULL COMMENT '메뉴 등록날짜', - `updated_date` datetime COMMENT '메뉴 수정날짜', - `cafe_id` binary(16) NOT NULL COMMENT '연관된 카페식별번호', - PRIMARY KEY (`menu_id`), + `price` decimal(10, 2) NOT NULL COMMENT '메뉴 가격', + `created_at` datetime NOT NULL COMMENT '메뉴 등록날짜', + `created_by` varchar(20) NOT NULL COMMENT '메뉴 등록자', + `updated_at` datetime COMMENT '메뉴 변경날짜', + `updated_by` varchar(20) NULL COMMENT '메뉴 변경자', + `cafe_id` bigint unsigned NOT NULL COMMENT '연관된 카페 ID', + PRIMARY KEY (`id`), KEY `cafe_id` (`cafe_id`), - FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`cafe_id`) + FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V003__Create_cafe_image.sql b/src/main/resources/db/migration/V003__Create_cafe_image.sql index 953db04..5f7b229 100644 --- a/src/main/resources/db/migration/V003__Create_cafe_image.sql +++ b/src/main/resources/db/migration/V003__Create_cafe_image.sql @@ -1,10 +1,12 @@ CREATE TABLE `cafe_image` ( - `cafe_img_id` binary(16) NOT NULL COMMENT '카페 이미지 식별번호', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '카페 이미지 ID', `img_url` varchar(255) NOT NULL COMMENT '이미지 경로', - `created_date` datetime NOT NULL COMMENT '이미지 등록날짜', - `updated_date` datetime COMMENT '이미지 수정날짜', - `cafe_id` binary(16) NOT NULL COMMENT '연관된 카페식별번호', - PRIMARY KEY (`cafe_img_id`), + `created_at` datetime NOT NULL COMMENT '이미지 등록날짜', + `created_by` varchar(20) NOT NULL COMMENT '이미지 등록자', + `updated_at` datetime COMMENT '이미지 변경날짜', + `updated_by` varchar(20) NULL COMMENT '이미지 변경자', + `cafe_id` bigint unsigned NOT NULL COMMENT '연관된 카페 ID', + PRIMARY KEY (`id`), KEY `cafe_id` (`cafe_id`), - FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`cafe_id`) + FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V004__Create_menu_option.sql b/src/main/resources/db/migration/V004__Create_menu_option.sql index 2ae7088..7d71d7f 100644 --- a/src/main/resources/db/migration/V004__Create_menu_option.sql +++ b/src/main/resources/db/migration/V004__Create_menu_option.sql @@ -1,10 +1,12 @@ CREATE TABLE `menu_option`( - `option_id` binary(16) NOT NULL COMMENT '옵션 식별번호', - `title`varchar(50) NOT NULL COMMENT '메뉴 옵션 이름', - `created_date` datetime NOT NULL COMMENT '옵션 등록날짜', - `updated_date` datetime COMMENT '옵션 수정날짜', - `menu_id` binary(16) NOT NULL COMMENT '연관된 카페 메뉴 식별번호', - PRIMARY KEY (`option_id`), + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '옵션 ID', + `title` varchar(50) NOT NULL COMMENT '메뉴 옵션 이름', + `created_at` datetime NOT NULL COMMENT '옵션 등록날짜', + `created_by` varchar(20) NOT NULL COMMENT '옵션 등록자', + `updated_at` datetime COMMENT '옵션 변경날짜', + `updated_by` varchar(20) NULL COMMENT '옵션 변경자', + `menu_id` bigint unsigned NOT NULL COMMENT '연관된 카페 메뉴 ID', + PRIMARY KEY (`id`), KEY `menu_id` (`menu_id`), - FOREIGN KEY (`menu_id`) REFERENCES `cafe_menu` (`menu_id`) + FOREIGN KEY (`menu_id`) REFERENCES `cafe_menu` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V005__Create_option_detail.sql b/src/main/resources/db/migration/V005__Create_option_detail.sql index 3e7a577..f68b2ce 100644 --- a/src/main/resources/db/migration/V005__Create_option_detail.sql +++ b/src/main/resources/db/migration/V005__Create_option_detail.sql @@ -1,11 +1,13 @@ CREATE TABLE `option_detail` ( - `option_detail_id` bigint NOT NULL COMMENT '옵션 상세 번호', + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '옵션 상세 ID', `name` varchar(50) NOT NULL COMMENT '옵션 상세명', - `extra` int NOT NULL COMMENT '옵션 추가 요금', - `created_date` datetime NOT NULL COMMENT '옵션 상세 등록날짜', - `updated_date` datetime COMMENT '옵션 상세 수정날짜', - `option_id` binary(16) NOT NULL COMMENT '연관된 옵션 식별번호', - PRIMARY KEY (`option_detail_id`), + `extra_price` decimal(10, 2) NOT NULL COMMENT '옵션 추가 요금', + `created_at` datetime NOT NULL COMMENT '옵션 상세 등록날짜', + `created_by` varchar(20) NOT NULL COMMENT '옵션 상세 등록자', + `updated_at` datetime COMMENT '옵션 상세 변경날짜', + `updated_by` varchar(20) NULL COMMENT '옵션 상세 변경자', + `option_id` bigint unsigned NOT NULL COMMENT '연관된 옵션 ID', + PRIMARY KEY (`id`), KEY `option_id` (`option_id`), - FOREIGN KEY (`option_id`) REFERENCES `menu_option` (`option_id`) + FOREIGN KEY (`option_id`) REFERENCES `menu_option` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V006__Create_user.sql b/src/main/resources/db/migration/V006__Create_user.sql deleted file mode 100644 index c90b186..0000000 --- a/src/main/resources/db/migration/V006__Create_user.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `user` ( - `user_id` binary(16) NOT NULL COMMENT '사용자 식별번호', - `email`varchar(50) NOT NULL COMMENT '사용자 이메일', - `password` varchar(100) NOT NULL COMMENT '계정 비밀번호', - `address` varchar(100) NOT NULL COMMENT '사용자 주소', - `phone_number` varchar(11) NOT NULL COMMENT '사용자 전화번호', - `role` varchar(20) NOT NULL COMMENT '사용자 권한', - `created_date` datetime NOT NULL COMMENT '사용자 등록날짜', - `updated_date` datetime COMMENT '사용자 수정날짜', - PRIMARY KEY (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V007__Create_review.sql b/src/main/resources/db/migration/V007__Create_review.sql deleted file mode 100644 index b68f6d3..0000000 --- a/src/main/resources/db/migration/V007__Create_review.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE `review` ( - `review_id` binary(16) NOT NULL COMMENT '리뷰 식별번호', - `content`varchar(255) NOT NULL COMMENT '리뷰 내용', - `img_url` varchar(255) NOT NULL COMMENT '리뷰 첨부사진 주소', - `rate` tinyint NOT NULL COMMENT '평가점수(0 ~ 5점)', - `created_date` datetime NOT NULL COMMENT '리뷰 등록날짜', - `updated_date` datetime COMMENT '리뷰 수정날짜', - `user_id` binary(16) NOT NULL COMMENT '리뷰 작성한 사용자 식별번호', - `cafe_id` binary(16) NOT NULL COMMENT '리뷰 대상 카페 식별번호', - PRIMARY KEY (`review_id`), - KEY `user_id` (`user_id`), - FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`), - KEY `cafe_id` (`cafe_id`), - FOREIGN KEY (`cafe_id`) REFERENCES `cafe` (`cafe_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V008__Create_cart.sql b/src/main/resources/db/migration/V008__Create_cart.sql deleted file mode 100644 index 65f2c46..0000000 --- a/src/main/resources/db/migration/V008__Create_cart.sql +++ /dev/null @@ -1,13 +0,0 @@ -CREATE TABLE `cart` ( - `cart_id` binary(16) NOT NULL COMMENT '장바구니 식별번호', - `cafe_name` varchar(20) NOT NULL COMMENT '장바구니에 담긴 카페 이름', - `check_ordered` tinyint NOT NULL COMMENT '장바구니의 주문 여부', - `total_price` int NOT NULL COMMENT '장바구니에 담긴 총 금액', - `created_date` datetime NOT NULL COMMENT '장바구니 등록날짜', - `updated_date` datetime COMMENT '장바구니 수정날짜', - `cafe_id` binary(16) NOT NULL COMMENT '장바구니에 담긴 카페 식별번호', - `user_id` binary(16) NOT NULL COMMENT '장바구니 주인 사용자 식별번호', - PRIMARY KEY (`cart_id`), - KEY `user_id` (`user_id`), - FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V009__Create_basket.sql b/src/main/resources/db/migration/V009__Create_basket.sql deleted file mode 100644 index 58e20e0..0000000 --- a/src/main/resources/db/migration/V009__Create_basket.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `basket` ( - `basket_id` binary(16) NOT NULL COMMENT '장바구니 품목 식별번호', - `menu_name` varchar(50) NOT NULL COMMENT '장바구니 품목 이름', - `menu_count` int NOT NULL COMMENT '장바구니 품목 개수', - `menu_price` int NOT NULL COMMENT '장바구니 품목 가격', - `created_date` datetime NOT NULL COMMENT '장바구니 품목 등록날짜', - `updated_date` datetime COMMENT '장바구니 품목 수정날짜', - `cart_id` binary(16) NOT NULL COMMENT '해당 품목이 담긴 장바구니 식별번호', - PRIMARY KEY (`basket_id`), - KEY `cart_id` (`cart_id`), - FOREIGN KEY (`cart_id`) REFERENCES `cart` (`cart_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V010__Create_basket_option.sql b/src/main/resources/db/migration/V010__Create_basket_option.sql deleted file mode 100644 index 3369b57..0000000 --- a/src/main/resources/db/migration/V010__Create_basket_option.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `basket_option` ( - `basket_option_id` binary(16) NOT NULL COMMENT '품목 추가옵션 식별번호', - `option_name`varchar(50) NOT NULL COMMENT '품목 추가옵션 내용', - `option_extra` int NOT NULL COMMENT '품목 추가옵션 추가요금', - `created_date` datetime NOT NULL COMMENT '품목 추가옵션 등록날짜', - `updated_date` datetime COMMENT '품목 추가옵션 수정날짜', - `basket_id` binary(16) NOT NULL COMMENT '추가옵션 대상 장바구니 품목 식별번호', - PRIMARY KEY (`basket_option_id`), - KEY `basket_id` (`basket_id`), - FOREIGN KEY (`basket_id`) REFERENCES `basket` (`basket_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file diff --git a/src/main/resources/db/migration/V011__Create_menu_order.sql b/src/main/resources/db/migration/V011__Create_menu_order.sql deleted file mode 100644 index ef18fc7..0000000 --- a/src/main/resources/db/migration/V011__Create_menu_order.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE `menu_order` ( - `order_id` binary(16) NOT NULL COMMENT '주문 식별번호', - `order_status` varchar(20) NOT NULL COMMENT '주문 상태', - `request_message` varchar(255) NOT NULL COMMENT '주문 요청사항', - `created_date` datetime NOT NULL COMMENT '주문 등록날짜', - `updated_date` datetime COMMENT '주문 수정날짜', - `cart_id` binary(16) NOT NULL COMMENT '주문된 카트 식별번호', - `user_id` binary(16) NOT NULL COMMENT '주문한 사용자 식별번호', - PRIMARY KEY (`order_id`), - KEY `cart_id` (`cart_id`), - FOREIGN KEY (`cart_id`) REFERENCES `cart` (`cart_id`), - KEY `user_id` (`user_id`), - FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; \ No newline at end of file From 9204bd48c541fe908838f53e388755dadc1a7148 Mon Sep 17 00:00:00 2001 From: beaniejoy Date: Tue, 5 Jul 2022 01:06:37 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[#7]=20feat:=20flyway=20migration=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - seed 적용 - 기존 DDL 내용 수정(update 관련 칼럼 추가) --- .../domain/cafe/controller/CafeController.kt | 2 +- .../domain/cafe/service/CafeService.kt | 7 +++-- src/main/resources/application.yml | 1 + .../db/migration/V001__Create_cafe.sql | 2 ++ .../db/migration/V002__Create_cafe_menu.sql | 2 ++ .../db/migration/V003__Create_cafe_image.sql | 2 ++ .../db/migration/V004__Create_menu_option.sql | 2 ++ .../migration/V005__Create_option_detail.sql | 2 ++ .../resources/db/seed/R__Insert_Seed_cafe.sql | 20 ++++++++++++++ .../db/seed/R__Insert_Seed_cafe_image.sql | 26 +++++++++++++++++++ .../db/seed/R__Insert_Seed_cafe_menu.sql | 22 ++++++++++++++++ 11 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/db/seed/R__Insert_Seed_cafe.sql create mode 100644 src/main/resources/db/seed/R__Insert_Seed_cafe_image.sql create mode 100644 src/main/resources/db/seed/R__Insert_Seed_cafe_menu.sql diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/controller/CafeController.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/controller/CafeController.kt index 22186b9..19d68f5 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/controller/CafeController.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/controller/CafeController.kt @@ -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 { return cafeService.getCafeList(pageable) } diff --git a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/service/CafeService.kt b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/service/CafeService.kt index 43ba67a..adeffc1 100644 --- a/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/service/CafeService.kt +++ b/src/main/java/io/beaniejoy/dongnecafe/domain/cafe/service/CafeService.kt @@ -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 { - val cafeListWithPagination = cafeRepository.findAll(pageable) + val cafeList: Page = cafeRepository.findAll(pageable) - return cafeListWithPagination.map { CafeSearchResponseDto.of(it) } + return cafeList.map { CafeSearchResponseDto.of(it) } } @Transactional(readOnly = true) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2252c8c..b923ae6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -14,4 +14,5 @@ spring: show-sql: true flyway: baseline-on-migrate: true + locations: classpath:db/migration,classpath:db/seed # baseline-version: 0 diff --git a/src/main/resources/db/migration/V001__Create_cafe.sql b/src/main/resources/db/migration/V001__Create_cafe.sql index 5941d25..0b07ee1 100644 --- a/src/main/resources/db/migration/V001__Create_cafe.sql +++ b/src/main/resources/db/migration/V001__Create_cafe.sql @@ -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 '카페명', diff --git a/src/main/resources/db/migration/V002__Create_cafe_menu.sql b/src/main/resources/db/migration/V002__Create_cafe_menu.sql index 40d197b..a2e4b0d 100644 --- a/src/main/resources/db/migration/V002__Create_cafe_menu.sql +++ b/src/main/resources/db/migration/V002__Create_cafe_menu.sql @@ -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 '카페 메뉴명', diff --git a/src/main/resources/db/migration/V003__Create_cafe_image.sql b/src/main/resources/db/migration/V003__Create_cafe_image.sql index 5f7b229..153e47d 100644 --- a/src/main/resources/db/migration/V003__Create_cafe_image.sql +++ b/src/main/resources/db/migration/V003__Create_cafe_image.sql @@ -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 '이미지 경로', diff --git a/src/main/resources/db/migration/V004__Create_menu_option.sql b/src/main/resources/db/migration/V004__Create_menu_option.sql index 7d71d7f..f39d6b3 100644 --- a/src/main/resources/db/migration/V004__Create_menu_option.sql +++ b/src/main/resources/db/migration/V004__Create_menu_option.sql @@ -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 '메뉴 옵션 이름', diff --git a/src/main/resources/db/migration/V005__Create_option_detail.sql b/src/main/resources/db/migration/V005__Create_option_detail.sql index f68b2ce..5a84814 100644 --- a/src/main/resources/db/migration/V005__Create_option_detail.sql +++ b/src/main/resources/db/migration/V005__Create_option_detail.sql @@ -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 '옵션 상세명', diff --git a/src/main/resources/db/seed/R__Insert_Seed_cafe.sql b/src/main/resources/db/seed/R__Insert_Seed_cafe.sql new file mode 100644 index 0000000..362b3c3 --- /dev/null +++ b/src/main/resources/db/seed/R__Insert_Seed_cafe.sql @@ -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); \ No newline at end of file diff --git a/src/main/resources/db/seed/R__Insert_Seed_cafe_image.sql b/src/main/resources/db/seed/R__Insert_Seed_cafe_image.sql new file mode 100644 index 0000000..6522029 --- /dev/null +++ b/src/main/resources/db/seed/R__Insert_Seed_cafe_image.sql @@ -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(); \ No newline at end of file diff --git a/src/main/resources/db/seed/R__Insert_Seed_cafe_menu.sql b/src/main/resources/db/seed/R__Insert_Seed_cafe_menu.sql new file mode 100644 index 0000000..2151e40 --- /dev/null +++ b/src/main/resources/db/seed/R__Insert_Seed_cafe_menu.sql @@ -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(); \ No newline at end of file