Skip to content

Commit

Permalink
fix: NotNull 칼럼에 대한 nullable false 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungJu committed Apr 1, 2024
1 parent e3ff36a commit 9fe8133
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -23,9 +23,9 @@ class CafeRoomEntity(
inverseJoinColumns = [JoinColumn(name = "genre_id")],
)
val genre: MutableSet<GenreEntity> = 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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ 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
val detail: CafeRoomReviewDetailEntity,
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "review_id")
val ratingFields: List<CafeRoomReviewRatingFieldEntity> = listOf(),
@Column(name = "created_at")
@Column(name = "created_at", nullable = false)
val createdAt: Date,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
58 changes: 27 additions & 31 deletions src/main/resources/db/migration/V1__init.sql
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
);

Expand All @@ -52,52 +52,52 @@ 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)
);

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)
);
Expand All @@ -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');

0 comments on commit 9fe8133

Please sign in to comment.