From 0e63e7a652a83ea7c68c6de27739bbb75e5c73e5 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Mon, 1 Apr 2024 18:26:13 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20flyway=20gradle=20task=20=EA=B5=AC?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 164 +++++++++++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 69 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a8ad9c8..f991b58 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,72 +1,85 @@ +import org.flywaydb.gradle.task.FlywayMigrateTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - id("org.springframework.boot") version "3.1.5" - id("io.spring.dependency-management") version "1.1.3" - kotlin("jvm") version "1.8.22" - kotlin("plugin.spring") version "1.8.22" - kotlin("plugin.jpa") version "1.8.22" - kotlin("kapt") version "1.8.22" - id("com.google.cloud.tools.jib") version "3.3.2" + id("org.springframework.boot") version "3.1.5" + id("io.spring.dependency-management") version "1.1.3" + kotlin("jvm") version "1.8.22" + kotlin("plugin.spring") version "1.8.22" + kotlin("plugin.jpa") version "1.8.22" + kotlin("kapt") version "1.8.22" + id("com.google.cloud.tools.jib") version "3.3.2" + id("co.uzzu.dotenv.gradle") version "4.0.0" + id("org.flywaydb.flyway") version "10.9.1" } group = "kr.nagaza" version = "0.0.1" java { - sourceCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_17 } repositories { - mavenCentral() + mavenCentral() } dependencies { - // Web Related Dependencies - implementation("org.springframework.boot:spring-boot-starter-actuator") - implementation("org.springframework.boot:spring-boot-starter-oauth2-client") - implementation("org.springframework.boot:spring-boot-starter-security") - implementation("org.springframework.boot:spring-boot-starter-web") - implementation("org.springframework.boot:spring-boot-starter-webflux") - implementation("com.nimbusds:nimbus-jose-jwt:9.37") - implementation("io.jsonwebtoken:jjwt-api:0.11.5") - runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5") - runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5") - - // Database Related Dependencies - implementation("org.springframework.boot:spring-boot-starter-data-jpa") - implementation("org.flywaydb:flyway-core") - implementation("org.flywaydb:flyway-mysql") - runtimeOnly("com.mysql:mysql-connector-j") - implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") - kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") - kapt("com.querydsl:querydsl-kotlin-codegen:5.0.0") - - // Test Related Dependencies - implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0") - testImplementation("org.springframework.boot:spring-boot-starter-test") - testImplementation("org.springframework.security:spring-security-test") - testImplementation("org.mockito:mockito-core:5.6.0") - testImplementation("org.mockito:mockito-junit-jupiter:5.6.0") - testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0") - - // Extra Utility Dependencies - implementation("com.github.f4b6a3:ulid-creator:5.2.0") - implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + // Web Related Dependencies + implementation("org.springframework.boot:spring-boot-starter-actuator") + implementation("org.springframework.boot:spring-boot-starter-oauth2-client") + implementation("org.springframework.boot:spring-boot-starter-security") + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-webflux") + implementation("com.nimbusds:nimbus-jose-jwt:9.37") + implementation("io.jsonwebtoken:jjwt-api:0.11.5") + runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5") + runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5") + // Database Related Dependencies + implementation("org.springframework.boot:spring-boot-starter-data-jpa") + + compileOnly("org.flywaydb:flyway-mysql") + implementation("org.flywaydb:flyway-core") + runtimeOnly("com.mysql:mysql-connector-j") + + implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") + kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") + kapt("com.querydsl:querydsl-kotlin-codegen:5.0.0") + + // Test Related Dependencies + implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0") + testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.security:spring-security-test") + testImplementation("org.mockito:mockito-core:5.6.0") + testImplementation("org.mockito:mockito-junit-jupiter:5.6.0") + testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0") + + // Extra Utility Dependencies + implementation("com.github.f4b6a3:ulid-creator:5.2.0") + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") +} + +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath("org.flywaydb:flyway-mysql:10.10.0") + } } tasks.withType { - kotlinOptions { - freeCompilerArgs += "-Xjsr305=strict" - jvmTarget = "17" - } + kotlinOptions { + freeCompilerArgs += "-Xjsr305=strict" + jvmTarget = "17" + } } tasks.withType { - useJUnitPlatform() + useJUnitPlatform() } val activeProfile: String? = System.getProperty("spring.profiles.active") @@ -74,27 +87,40 @@ val repoURL: String? = System.getProperty("imageName") val imageTag: String? = System.getProperty("imageTag") jib { - from { - image = "amazoncorretto:17-alpine3.17-jdk" - } - to { - image = repoURL - tags = setOf(imageTag) - } - container { - jvmFlags = listOf( - "-Dspring.profiles.active=${activeProfile}", - "-Dserver.port=8080", - "-Djava.security.egd=file:/dev/./urandom", - "-Dfile.encoding=UTF-8", - "-XX:+UnlockExperimentalVMOptions", - "-XX:+UseContainerSupport", - "-XX:+UseG1GC", - "-XX:InitialHeapSize=2g", - "-XX:MaxHeapSize=2g", - "-XX:+DisableExplicitGC", //System.gc() 방어 - "-server", - ) - ports = listOf("8080") - } + from { + image = "amazoncorretto:17-alpine3.17-jdk" + } + to { + image = repoURL + tags = setOf(imageTag) + } + container { + jvmFlags = + listOf( + "-Dspring.profiles.active=$activeProfile", + "-Dserver.port=8080", + "-Djava.security.egd=file:/dev/./urandom", + "-Dfile.encoding=UTF-8", + "-XX:+UnlockExperimentalVMOptions", + "-XX:+UseContainerSupport", + "-XX:+UseG1GC", + "-XX:InitialHeapSize=2g", + "-XX:MaxHeapSize=2g", + "-XX:+DisableExplicitGC", // System.gc() 방어 + "-server", + ) + ports = listOf("8080") + } +} + +flyway { + url = env.MYSQL_URL.value + "?permitMysqlScheme=true" + user = env.MYSQL_USERNAME.value + password = env.MYSQL_PASSWORD.value + locations = arrayOf("classpath:db/migration") + driver = "com.mysql.cj.jdbc.Driver" +} + +tasks.withType { + dependsOn("classes") } From f5a03141843a3a6cef750dfa2074e8f1ca8d09b0 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Mon, 1 Apr 2024 18:26:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20V1=20Init=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=EA=B7=B8=EB=A0=88=EC=9D=B4=EC=85=98=EC=9D=84=20=EC=83=88?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/db/migration/V1__.sql | 122 ++++++++++++++++++ src/main/resources/db/migration/V1__init.sql | 127 ------------------- 2 files changed, 122 insertions(+), 127 deletions(-) create mode 100644 src/main/resources/db/migration/V1__.sql delete mode 100644 src/main/resources/db/migration/V1__init.sql diff --git a/src/main/resources/db/migration/V1__.sql b/src/main/resources/db/migration/V1__.sql new file mode 100644 index 0000000..6a8a284 --- /dev/null +++ b/src/main/resources/db/migration/V1__.sql @@ -0,0 +1,122 @@ +CREATE TABLE app_info +( + app_version VARCHAR(255) NOT NULL, + in_service BIT(1) NULL, + CONSTRAINT pk_app_info PRIMARY KEY (app_version) +); + +CREATE TABLE cafe +( + cafe_id VARCHAR(255) NOT NULL, + franchise_id VARCHAR(255) NULL, + cafe_name VARCHAR(255) NULL, + `description` VARCHAR(255) NULL, + address VARCHAR(255) NULL, + web_url VARCHAR(255) NULL, + phone_number VARCHAR(255) NULL, + location_lat DOUBLE NULL, + location_lng DOUBLE NULL, + addr_1 VARCHAR(255) NULL, + addr_2 VARCHAR(255) NULL, + CONSTRAINT pk_cafe PRIMARY KEY (cafe_id) +); + +CREATE TABLE cafe_room +( + room_id VARCHAR(255) NOT NULL, + cafe_id VARCHAR(255) NULL, + title VARCHAR(255) NULL, + `description` VARCHAR(255) NULL, + timeout INT NULL, + recommend_user INT NULL, + room_img_url VARCHAR(255) NULL, + created_at datetime NULL, + updated_at datetime NULL, + CONSTRAINT pk_cafe_room PRIMARY KEY (room_id) +); + +CREATE TABLE cafe_room_genre +( + genre_id VARCHAR(255) NOT NULL, + room_id VARCHAR(255) NOT NULL, + CONSTRAINT pk_cafe_room_genre PRIMARY KEY (genre_id, room_id) +); + +CREATE TABLE cafe_room_like +( + room_id VARCHAR(255) NOT NULL, + user_id VARCHAR(255) NOT NULL, + CONSTRAINT pk_cafe_room_like PRIMARY KEY (room_id, user_id) +); + +CREATE TABLE cafe_room_review +( + review_id VARCHAR(255) NOT NULL, + room_id VARCHAR(255) NULL, + user_id VARCHAR(255) NULL, + detail_review_id VARCHAR(255) NULL, + created_at datetime NULL, + CONSTRAINT pk_cafe_room_review PRIMARY KEY (review_id) +); + +CREATE TABLE cafe_room_review_det +( + review_id VARCHAR(255) NOT NULL, + user_cnt INT NULL, + is_cleared BIT(1) NULL, + is_life_theme BIT(1) NULL, + used_hint_cnt INT NULL, + content VARCHAR(255) NULL, + CONSTRAINT pk_cafe_room_review_det PRIMARY KEY (review_id) +); + +CREATE TABLE cafe_room_review_rating_field +( + rating_field_id VARCHAR(255) NOT NULL, + review_id VARCHAR(255) NULL, + type TINYINT NULL, + value INT NULL, + CONSTRAINT pk_cafe_room_review_rating_field PRIMARY KEY (rating_field_id) +); + +CREATE TABLE genre +( + genre_id VARCHAR(255) NOT NULL, + name VARCHAR(255) NULL, + CONSTRAINT pk_genre PRIMARY KEY (genre_id) +); + +CREATE TABLE social_user +( + social_provider VARCHAR(255) NOT NULL, + social_identifier VARCHAR(255) NOT NULL, + user_id VARCHAR(255) NULL, + CONSTRAINT pk_social_user PRIMARY KEY (social_provider, social_identifier) +); + +CREATE TABLE user +( + user_id VARCHAR(255) NOT NULL, + nickname VARCHAR(255) NULL, + profile_img_url VARCHAR(255) NULL, + CONSTRAINT pk_user PRIMARY KEY (user_id) +); + +ALTER TABLE cafe_room_review + ADD CONSTRAINT FK_CAFE_ROOM_REVIEW_ON_DETAIL_REVIEW FOREIGN KEY (detail_review_id) REFERENCES cafe_room_review_det (review_id); + +ALTER TABLE cafe_room_review + ADD CONSTRAINT FK_CAFE_ROOM_REVIEW_ON_ROOM FOREIGN KEY (room_id) REFERENCES cafe_room (room_id); + +ALTER TABLE cafe_room_review_rating_field + ADD CONSTRAINT FK_CAFE_ROOM_REVIEW_RATING_FIELD_ON_REVIEW FOREIGN KEY (review_id) REFERENCES cafe_room_review (review_id); + +ALTER TABLE cafe_room_genre + ADD CONSTRAINT fk_cafroogen_on_cafe_room_entity FOREIGN KEY (room_id) REFERENCES cafe_room (room_id); + +ALTER TABLE cafe_room_genre + ADD CONSTRAINT fk_cafroogen_on_genre_entity FOREIGN KEY (genre_id) REFERENCES genre (genre_id); + +INSERT INTO user (user_id, nickname, profile_img_url) +VALUES ('01HDNFJHCNS5E2W35YTB030TJ8', '테스트용사용자', + 'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png'); diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql deleted file mode 100644 index e215986..0000000 --- a/src/main/resources/db/migration/V1__init.sql +++ /dev/null @@ -1,127 +0,0 @@ -CREATE TABLE app_info -( - app_version VARCHAR(64) NOT NULL COMMENT '앱버전', - in_service BOOLEAN NOT NULL COMMENT '서비스 여부', - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_At DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY app_info_pk (app_version) -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci COMMENT ='앱정보'; - -CREATE TABLE user -( - user_id CHAR(26) NOT NULL, - nickname VARCHAR(64) NOT NULL, - profile_img_url VARCHAR(128), - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (user_id) -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '유저테이블'; - -CREATE TABLE social_user -( - social_provider VARCHAR(16) NOT NULL, - social_identifier VARCHAR(128) NOT NULL, - user_id CHAR(26) NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (social_provider, social_identifier), - FOREIGN KEY social_user_fk1 (user_id) REFERENCES user (user_id) ON DELETE CASCADE -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '소셜로그인'; - -CREATE TABLE cafe_franchise -( - franchise_id CHAR(26) NOT NULL, - franchise_name VARCHAR(64) NOT NULL, - PRIMARY KEY (franchise_id) -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '프랜차이즈'; - -CREATE TABLE cafe -( - cafe_id CHAR(26) NOT NULL, - franchise_id CHAR(26) DEFAULT NULL, - cafe_name VARCHAR(128) NOT NULL, - description TEXT NOT NULL, - address VARCHAR(255), - web_url VARCHAR(255), - phone_number VARCHAR(36), - location_lat DOUBLE, - location_lng DOUBLE, - addr_1 VARCHAR(16), - addr_2 VARCHAR(16), - PRIMARY KEY (cafe_id), - FOREIGN KEY cafe_fk1 (franchise_id) REFERENCES cafe_franchise (franchise_id) ON DELETE SET NULL -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '방탈출카페'; - -CREATE TABLE cafe_room -( - room_id CHAR(26) NOT NULL, - cafe_id CHAR(26) NOT NULL, - genre VARCHAR(16) NOT NULL, - timeout INT NOT NULL, - recommend_user INT NOT NULL, - room_img_url VARCHAR(128), - description TEXT NOT NULL, - PRIMARY KEY (room_id), - FOREIGN KEY cafe_room_fk1 (cafe_id) REFERENCES cafe (cafe_id) ON DELETE CASCADE -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '방탈출카페방'; - -CREATE TABLE cafe_room_like -( - room_id CHAR(26) NOT NULL, - user_id CHAR(26) NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (room_id, user_id), - FOREIGN KEY cafe_room_like_fk1 (room_id) REFERENCES cafe_room (room_id) ON DELETE CASCADE, - FOREIGN KEY cafe_room_like_fk2 (user_id) REFERENCES user (user_id) ON DELETE CASCADE -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '방탈출카페좋아요'; - -CREATE TABLE cafe_room_review -( - review_id CHAR(26) NOT NULL, - room_id CHAR(26) NOT NULL, - user_id CHAR(26) NOT NULL, - content TEXT NOT NULL, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (review_id), - FOREIGN KEY cafe_room_review_fk1 (room_id) REFERENCES cafe_room (room_id), - FOREIGN KEY cafe_room_review_fk2 (user_id) REFERENCES user (user_id) -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '방탈출카페방리뷰'; - -CREATE TABLE cafe_room_review_det -( - review_id CHAR(26) NOT NULL, - user_cnt INT, - is_cleared BOOL, - is_life_theme BOOL, - used_hint_cnt INT, - difficulty_point INT, - activity_point INT, - interior_point INT, - production_point INT, - device_ratio DOUBLE, - PRIMARY KEY (review_id), - FOREIGN KEY cafe_room_review_det_fk1 (review_id) REFERENCES cafe_room_review (review_id) ON DELETE CASCADE -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '방탈출카페방리뷰디테일'; - -CREATE TABLE cafe_room_review_det_opt -( - review_id CHAR(26) NOT NULL, - option_type VARCHAR(16) NOT NULL, - option_value BOOL NOT NULL, - PRIMARY KEY (review_id, option_type), - FOREIGN KEY cafe_room_review_det_opt_fk1 (review_id) REFERENCES cafe_room_review (review_id) ON DELETE CASCADE -) DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_unicode_ci comment '방탈출카페방리뷰디테일선택'; - -#MOCK DML -INSERT INTO user (user_id, nickname, profile_img_url) -VALUES ('01HDNFJHCNS5E2W35YTB030TJ8', '테스트용사용자', - 'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png'); From e3ff36a55c0afc30689b581689af6c597fe4fcf9 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Mon, 1 Apr 2024 18:35:49 +0900 Subject: [PATCH 3/4] chore: rename V1 migration script to init --- src/main/resources/db/migration/{V1__.sql => V1__init.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/db/migration/{V1__.sql => V1__init.sql} (100%) diff --git a/src/main/resources/db/migration/V1__.sql b/src/main/resources/db/migration/V1__init.sql similarity index 100% rename from src/main/resources/db/migration/V1__.sql rename to src/main/resources/db/migration/V1__init.sql From 9fe8133464234289f8f90ad2e1dbec7b8b28fcd4 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Mon, 1 Apr 2024 18:53:31 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20NotNull=20=EC=B9=BC=EB=9F=BC?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20nullable=20false=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/jpa/entity/CafeEntity.kt | 70 ++++++++----------- .../jpa/entity/CafeRoomEntity.kt | 10 +-- .../jpa/entity/CafeRoomReviewDetailEntity.kt | 10 +-- .../jpa/entity/CafeRoomReviewEntity.kt | 6 +- .../entity/CafeRoomReviewRatingFieldEntity.kt | 6 +- .../infrastructure/jpa/entity/GenreEntity.kt | 2 +- .../jpa/entity/SocialUserEntity.kt | 26 +++---- .../infrastructure/jpa/entity/UserEntity.kt | 26 +++---- src/main/resources/db/migration/V1__init.sql | 58 +++++++-------- 9 files changed, 101 insertions(+), 113 deletions(-) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt index 6e3f7e2..c307349 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeEntity.kt @@ -10,64 +10,56 @@ class CafeEntity( @Id @Column(name = "cafe_id") val cafeId: String, - - @Column(name = "franchise_id") + @Column(name = "franchise_id", nullable = false) val franchiseId: String, - - @Column(name = "cafe_name") + @Column(name = "cafe_name", nullable = false) val cafeName: String, - - @Column(name = "description") + @Column(name = "description", nullable = false) val description: String, - @Column(name = "address") val address: String?, - @Column(name = "web_url") val webUrl: String?, - @Column(name = "phone_number") val phoneNumber: String?, - @Column(name = "location_lat") val locationLat: Double?, - @Column(name = "location_lng") val locationLng: Double?, - @Column(name = "addr_1") val addressOne: String?, - @Column(name = "addr_2") val addressTwo: String?, ) { - fun toModel() = Cafe( - id = cafeId, - franchiseId = franchiseId, - name = cafeName, - description = description, - address = address, - webUrl = webUrl, - phoneNumber = phoneNumber, - locationLat = locationLat, - locationLng = locationLng, - addressOne = addressOne, - addressTwo = addressTwo, - ) + fun toModel() = + Cafe( + id = cafeId, + franchiseId = franchiseId, + name = cafeName, + description = description, + address = address, + webUrl = webUrl, + phoneNumber = phoneNumber, + locationLat = locationLat, + locationLng = locationLng, + addressOne = addressOne, + addressTwo = addressTwo, + ) companion object { - fun fromModel(cafe: Cafe) = CafeEntity( - cafeId = cafe.id, - franchiseId = cafe.franchiseId, - cafeName = cafe.name, - description = cafe.description, - address = cafe.address, - webUrl = cafe.webUrl, - phoneNumber = cafe.phoneNumber, - locationLat = cafe.locationLat, - locationLng = cafe.locationLng, - addressOne = cafe.addressOne, - addressTwo = cafe.addressTwo, - ) + fun fromModel(cafe: Cafe) = + CafeEntity( + cafeId = cafe.id, + franchiseId = cafe.franchiseId, + cafeName = cafe.name, + description = cafe.description, + address = cafe.address, + webUrl = cafe.webUrl, + phoneNumber = cafe.phoneNumber, + locationLat = cafe.locationLat, + locationLng = cafe.locationLng, + addressOne = cafe.addressOne, + addressTwo = cafe.addressTwo, + ) } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt index 97dba0c..208d08e 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt @@ -10,11 +10,11 @@ class CafeRoomEntity( @Id @Column(name = "room_id") val roomId: String, - @Column(name = "cafe_id") + @Column(name = "cafe_id", nullable = false) val cafeId: String, - @Column(name = "title") + @Column(name = "title", nullable = false) val title: String, - @Column(name = "description") + @Column(name = "description", nullable = false) val description: String, @ManyToMany @JoinTable( @@ -23,9 +23,9 @@ class CafeRoomEntity( inverseJoinColumns = [JoinColumn(name = "genre_id")], ) val genre: MutableSet = mutableSetOf(), - @Column(name = "timeout") + @Column(name = "timeout", nullable = false) val timeout: Int, - @Column(name = "recommend_user") + @Column(name = "recommend_user", nullable = false) val recommendUserCnt: Int, @Column(name = "room_img_url") val roomImgUrl: String?, diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt index eaa2715..592420f 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt @@ -9,14 +9,14 @@ class CafeRoomReviewDetailEntity( @Id @Column(name = "review_id") val reviewId: String, - @Column(name = "user_cnt") + @Column(name = "user_cnt", nullable = false) val userCnt: Int, - @Column(name = "is_cleared") + @Column(name = "is_cleared", nullable = false) val isCleared: Boolean, - @Column(name = "is_life_theme") + @Column(name = "is_life_theme", nullable = false) val isLifeTheme: Boolean, - @Column(name = "used_hint_cnt") + @Column(name = "used_hint_cnt", nullable = false) val usedHintCnt: Int, - @Column(name = "content") + @Column(name = "content", nullable = false) val content: String, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt index ab7b421..457dd81 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt @@ -8,9 +8,9 @@ class CafeRoomReviewEntity( @Id @Column(name = "review_id") val reviewId: String, - @Column(name = "room_id") + @Column(name = "room_id", nullable = false) val roomId: String, - @Column(name = "user_id") + @Column(name = "user_id", nullable = false) val userId: String, @OneToOne @PrimaryKeyJoinColumn @@ -18,6 +18,6 @@ class CafeRoomReviewEntity( @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "review_id") val ratingFields: List = listOf(), - @Column(name = "created_at") + @Column(name = "created_at", nullable = false) val createdAt: Date, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt index 52d1e02..fd234fe 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt @@ -10,10 +10,10 @@ class CafeRoomReviewRatingFieldEntity( @Id @Column(name = "rating_field_id") val ratingFieldId: String, - @Column(name = "review_id") + @Column(name = "review_id", nullable = false) val reviewId: String, - @Column(name = "type") + @Column(name = "type", nullable = false) val fieldType: RatingFieldType, - @Column(name = "value") + @Column(name = "value", nullable = false) val value: Int, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt index 9ab11fd..9fdc3de 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt @@ -10,7 +10,7 @@ class GenreEntity( @Id @Column(name = "genre_id") val genreId: String, - @Column(name = "name") + @Column(name = "name", nullable = false) val name: String, ) { fun toModel(): Genre { diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt index a309152..de3f8a9 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/SocialUserEntity.kt @@ -12,26 +12,26 @@ class SocialUserEntity( @Enumerated(EnumType.STRING) @Column(name = "social_provider") val socialProvider: SocialProvider, - @Id @Column(name = "social_identifier") val socialIdentifier: String, - - @Column(name = "user_id") + @Column(name = "user_id", nullable = false) val userId: String, ) { - fun toModel() = SocialUser( - provider = socialProvider, - identifier = socialIdentifier, - userId = userId, - ) + fun toModel() = + SocialUser( + provider = socialProvider, + identifier = socialIdentifier, + userId = userId, + ) companion object { - fun fromModel(socialUser: SocialUser) = SocialUserEntity( - socialProvider = socialUser.provider, - socialIdentifier = socialUser.identifier, - userId = socialUser.userId, - ) + fun fromModel(socialUser: SocialUser) = + SocialUserEntity( + socialProvider = socialUser.provider, + socialIdentifier = socialUser.identifier, + userId = socialUser.userId, + ) } override fun equals(other: Any?): Boolean { diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt index c825764..f7c7b96 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/UserEntity.kt @@ -10,24 +10,24 @@ class UserEntity( @Id @Column(name = "user_id") val userId: String, - - @Column(name = "nickname") + @Column(name = "nickname", nullable = false) val nickname: String, - @Column(name = "profile_img_url") val profileImageUrl: String?, ) { - fun toModel() = User( - userId = userId, - nickname = nickname, - profileImageUrl = profileImageUrl, - ) + fun toModel() = + User( + userId = userId, + nickname = nickname, + profileImageUrl = profileImageUrl, + ) companion object { - fun fromModel(model: User) = UserEntity( - userId = model.userId, - nickname = model.nickname, - profileImageUrl = model.profileImageUrl, - ) + fun fromModel(model: User) = + UserEntity( + userId = model.userId, + nickname = model.nickname, + profileImageUrl = model.profileImageUrl, + ) } } diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql index 6a8a284..50e6f4a 100644 --- a/src/main/resources/db/migration/V1__init.sql +++ b/src/main/resources/db/migration/V1__init.sql @@ -1,21 +1,21 @@ CREATE TABLE app_info ( app_version VARCHAR(255) NOT NULL, - in_service BIT(1) NULL, + in_service BIT(1) NULL, CONSTRAINT pk_app_info PRIMARY KEY (app_version) ); CREATE TABLE cafe ( cafe_id VARCHAR(255) NOT NULL, - franchise_id VARCHAR(255) NULL, - cafe_name VARCHAR(255) NULL, - `description` VARCHAR(255) NULL, + franchise_id VARCHAR(255) NOT NULL, + cafe_name VARCHAR(255) NOT NULL, + `description` VARCHAR(255) NOT NULL, address VARCHAR(255) NULL, web_url VARCHAR(255) NULL, phone_number VARCHAR(255) NULL, - location_lat DOUBLE NULL, - location_lng DOUBLE NULL, + location_lat DOUBLE NULL, + location_lng DOUBLE NULL, addr_1 VARCHAR(255) NULL, addr_2 VARCHAR(255) NULL, CONSTRAINT pk_cafe PRIMARY KEY (cafe_id) @@ -24,14 +24,14 @@ CREATE TABLE cafe CREATE TABLE cafe_room ( room_id VARCHAR(255) NOT NULL, - cafe_id VARCHAR(255) NULL, - title VARCHAR(255) NULL, - `description` VARCHAR(255) NULL, - timeout INT NULL, - recommend_user INT NULL, + cafe_id VARCHAR(255) NOT NULL, + title VARCHAR(255) NOT NULL, + `description` VARCHAR(255) NOT NULL, + timeout INT NOT NULL, + recommend_user INT NOT NULL, room_img_url VARCHAR(255) NULL, - created_at datetime NULL, - updated_at datetime NULL, + created_at datetime NULL, + updated_at datetime NULL, CONSTRAINT pk_cafe_room PRIMARY KEY (room_id) ); @@ -52,37 +52,37 @@ CREATE TABLE cafe_room_like CREATE TABLE cafe_room_review ( review_id VARCHAR(255) NOT NULL, - room_id VARCHAR(255) NULL, - user_id VARCHAR(255) NULL, + room_id VARCHAR(255) NOT NULL, + user_id VARCHAR(255) NOT NULL, detail_review_id VARCHAR(255) NULL, - created_at datetime NULL, + created_at datetime NOT NULL, CONSTRAINT pk_cafe_room_review PRIMARY KEY (review_id) ); CREATE TABLE cafe_room_review_det ( review_id VARCHAR(255) NOT NULL, - user_cnt INT NULL, - is_cleared BIT(1) NULL, - is_life_theme BIT(1) NULL, - used_hint_cnt INT NULL, - content VARCHAR(255) NULL, + user_cnt INT NOT NULL, + is_cleared BIT(1) NOT NULL, + is_life_theme BIT(1) NOT NULL, + used_hint_cnt INT NOT NULL, + content VARCHAR(255) NOT NULL, CONSTRAINT pk_cafe_room_review_det PRIMARY KEY (review_id) ); CREATE TABLE cafe_room_review_rating_field ( rating_field_id VARCHAR(255) NOT NULL, - review_id VARCHAR(255) NULL, - type TINYINT NULL, - value INT NULL, + review_id VARCHAR(255) NOT NULL, + type SMALLINT NOT NULL, + value INT NOT NULL, CONSTRAINT pk_cafe_room_review_rating_field PRIMARY KEY (rating_field_id) ); CREATE TABLE genre ( genre_id VARCHAR(255) NOT NULL, - name VARCHAR(255) NULL, + name VARCHAR(255) NOT NULL, CONSTRAINT pk_genre PRIMARY KEY (genre_id) ); @@ -90,14 +90,14 @@ CREATE TABLE social_user ( social_provider VARCHAR(255) NOT NULL, social_identifier VARCHAR(255) NOT NULL, - user_id VARCHAR(255) NULL, + user_id VARCHAR(255) NOT NULL, CONSTRAINT pk_social_user PRIMARY KEY (social_provider, social_identifier) ); CREATE TABLE user ( user_id VARCHAR(255) NOT NULL, - nickname VARCHAR(255) NULL, + nickname VARCHAR(255) NOT NULL, profile_img_url VARCHAR(255) NULL, CONSTRAINT pk_user PRIMARY KEY (user_id) ); @@ -116,7 +116,3 @@ ALTER TABLE cafe_room_genre ALTER TABLE cafe_room_genre ADD CONSTRAINT fk_cafroogen_on_genre_entity FOREIGN KEY (genre_id) REFERENCES genre (genre_id); - -INSERT INTO user (user_id, nickname, profile_img_url) -VALUES ('01HDNFJHCNS5E2W35YTB030TJ8', '테스트용사용자', - 'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png');