Add DB Schema
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.yam.app.account.domain;
|
||||
|
||||
import com.yam.app.common.EntityStatus;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
@@ -21,6 +22,7 @@ public final class Account {
|
||||
private LocalDateTime withdrawalAt;
|
||||
private boolean withdraw = false;
|
||||
private Role role;
|
||||
private EntityStatus status = EntityStatus.ALIVE;
|
||||
|
||||
private Account(String email, String password) {
|
||||
this.email = email;
|
||||
|
||||
14
src/main/java/com/yam/app/common/EntityStatus.java
Normal file
14
src/main/java/com/yam/app/common/EntityStatus.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yam.app.common;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum EntityStatus {
|
||||
ALIVE, DELETED;
|
||||
|
||||
public static EntityStatus findStatus(String status) {
|
||||
return Arrays.stream(EntityStatus.values())
|
||||
.filter(s -> s.name().equals(status))
|
||||
.findFirst()
|
||||
.orElseThrow(IllegalArgumentException::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.yam.app.common.configuration;
|
||||
|
||||
import com.yam.app.common.EntityStatus;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
|
||||
public final class EntityStatusTypeHandler implements TypeHandler<EntityStatus> {
|
||||
|
||||
@Override
|
||||
public void setParameter(PreparedStatement ps, int i,
|
||||
EntityStatus parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setString(i, parameter.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityStatus getResult(ResultSet rs, String columnName) throws SQLException {
|
||||
return EntityStatus.findStatus(rs.getString(columnName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityStatus getResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
return EntityStatus.findStatus(rs.getString(columnIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityStatus getResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
return EntityStatus.findStatus(cs.getString(columnIndex));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yam.app.member.domain;
|
||||
|
||||
import com.yam.app.common.EntityStatus;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -10,6 +11,7 @@ public final class Member {
|
||||
private Long id;
|
||||
private String nickname;
|
||||
private String image;
|
||||
private EntityStatus status = EntityStatus.ALIVE;
|
||||
|
||||
public Member(String nickname, String image) {
|
||||
this.nickname = nickname;
|
||||
|
||||
@@ -13,16 +13,17 @@
|
||||
joined_at = #{joinedAt},
|
||||
role = #{role},
|
||||
last_modified_at = NOW(),
|
||||
member_id = #{memberId}
|
||||
member_id = #{memberId},
|
||||
status = #{status}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<insert id="save" parameterType="com.yam.app.account.domain.Account">
|
||||
INSERT
|
||||
INTO ACCOUNT(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||
password, withdraw, role)
|
||||
password, withdraw, role, status)
|
||||
VALUES (#{email}, #{emailCheckToken}, #{emailCheckTokenGeneratedAt}, #{emailVerified},
|
||||
#{password}, #{withdraw}, #{role})
|
||||
#{password}, #{withdraw}, #{role}, #{status})
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -5,14 +5,15 @@
|
||||
|
||||
<insert id="save" parameterType="com.yam.app.member.domain.Member">
|
||||
INSERT
|
||||
INTO MEMBER(nickname, image)
|
||||
VALUES (#{nickname}, #{image})
|
||||
INTO MEMBER(nickname, image, status)
|
||||
VALUES (#{nickname}, #{image}, #{status})
|
||||
</insert>
|
||||
|
||||
<update id="update" parameterType="com.yam.app.member.domain.Member">
|
||||
UPDATE MEMBER
|
||||
SET nickname = #{nickname},
|
||||
image = #{image}
|
||||
image = #{image},
|
||||
status = #{status}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ create table account
|
||||
withdraw boolean not null,
|
||||
withdrawal_at timestamp,
|
||||
member_id bigint,
|
||||
status varchar(255) not null,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
@@ -19,11 +20,63 @@ create table member(
|
||||
id bigint generated by default as identity,
|
||||
nickname varchar(255) not null,
|
||||
image varchar(255) not null,
|
||||
status varchar(255) not null,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
alter table account
|
||||
add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
||||
create table article (
|
||||
id bigint generated by default as identity,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
image varchar(255) not null,
|
||||
modified_at timestamp,
|
||||
status varchar(255) not null,
|
||||
title varchar(255) not null,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
alter table account
|
||||
add constraint FKr5j0huynd7nsv1s7e9vb8qvwo foreign key (member_id) references member;
|
||||
create table article_likes (
|
||||
id bigint generated by default as identity,
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
create table article_tag (
|
||||
id bigint generated by default as identity,
|
||||
article_id bigint not null,
|
||||
tag_id bigint not null,
|
||||
primary key (id));
|
||||
|
||||
create table comment (
|
||||
id bigint generated by default as identity,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
modified_at timestamp,
|
||||
status varchar(255),
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
create table comment_likes (
|
||||
id bigint generated by default as identity,
|
||||
comment_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id));
|
||||
|
||||
create table tag (
|
||||
id bigint generated by default as identity,
|
||||
name varchar(255) not null,
|
||||
primary key (id));
|
||||
|
||||
alter table account add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
||||
alter table account add constraint FKr5j0huynd7nsv1s7e9vb8qvwo foreign key (member_id) references member;
|
||||
alter table tag add constraint UK_1wdpsed5kna2y38hnbgrnhi5b unique (name);
|
||||
alter table article add constraint FK6l9vkfd5ixw8o8kph5rj1k7gu foreign key (member_id) references member;
|
||||
alter table article_likes add constraint FK1wt0ww82gfxkuxw3ghxmp55xy foreign key (article_id) references article;
|
||||
alter table article_likes add constraint FKkipxs7p8nrjd4537f3k8rexh5 foreign key (member_id) references member;
|
||||
alter table article_tag add constraint FKenqeees0y8hkm7x1p1ittuuye foreign key (article_id) references article;
|
||||
alter table article_tag add constraint FKesqp7s9jj2wumlnhssbme5ule foreign key (tag_id) references tag;
|
||||
alter table comment add constraint FK5yx0uphgjc6ik6hb82kkw501y foreign key (article_id) references article;
|
||||
alter table comment add constraint FKmrrrpi513ssu63i2783jyiv9m foreign key (member_id) references member;
|
||||
alter table comment_likes add constraint FKd0epu3dcjc57pwe7lt5jgfqsi foreign key (comment_id) references comment;
|
||||
alter table comment_likes add constraint FK7mxs5jtimpj71miv2r0fp6r8p foreign key (member_id) references member;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||
joined_at, last_modified_at, password, withdraw, role)
|
||||
joined_at, last_modified_at, password, withdraw, role, status)
|
||||
values ('jiwonDev@gmail.com', 'emailchecktoken', now(), false, now(), now(), 'password!',
|
||||
false, 'DEFAULT'),
|
||||
false, 'DEFAULT', 'ALIVE'),
|
||||
('loginCheck@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||
'$2a$10$EqbMbYB0vcZnuA5CClqa9uiLDnjA6pCjxn208ZchzA2q3ofqnkhcq',
|
||||
false, 'DEFAULT');
|
||||
false, 'DEFAULT', 'ALIVE');
|
||||
|
||||
insert into member(nickname, image)
|
||||
values ('rebwon', 'temp.png');
|
||||
insert into member(nickname, image, status)
|
||||
values ('rebwon', 'temp.png', 'ALIVE');
|
||||
|
||||
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||
joined_at, last_modified_at, password, withdraw, role, member_id)
|
||||
joined_at, last_modified_at, password, withdraw, role, member_id, status)
|
||||
values ('rebwon@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||
'$2a$10$EqbMbYB0vcZnuA5CClqa9uiLDnjA6pCjxn208ZchzA2q3ofqnkhcq',
|
||||
false, 'DEFAULT', 1);
|
||||
false, 'DEFAULT', 1, 'ALIVE');
|
||||
|
||||
Reference in New Issue
Block a user