From 81cb45d74ad9b4abe432894ccd9d76d91e594278 Mon Sep 17 00:00:00 2001 From: Rebwon Date: Thu, 21 Oct 2021 14:33:20 +0900 Subject: [PATCH] Refactor mapper query --- .../mapper/xml/AccountCommandMapper.xml | 4 +- .../mapper/xml/AccountQueryMapper.xml | 4 +- .../mapper/xml/ArticleCommandMapper.xml | 2 +- .../resources/mapper/xml/ArticleTagMapper.xml | 2 +- .../mapper/xml/CommentCommandMapper.xml | 6 +- .../mapper/xml/CommentQueryMapper.xml | 6 +- .../mapper/xml/MemberCommandMapper.xml | 4 +- src/main/resources/mapper/xml/TagMapper.xml | 4 +- src/main/resources/schema-mysql.sql | 66 ++++++++----------- 9 files changed, 44 insertions(+), 54 deletions(-) diff --git a/src/main/resources/mapper/xml/AccountCommandMapper.xml b/src/main/resources/mapper/xml/AccountCommandMapper.xml index 1d967b3..efb19f7 100644 --- a/src/main/resources/mapper/xml/AccountCommandMapper.xml +++ b/src/main/resources/mapper/xml/AccountCommandMapper.xml @@ -3,7 +3,7 @@ - UPDATE ACCOUNT + UPDATE account SET email = #{email}, email_check_token = #{emailCheckToken}, email_check_token_generated_at = #{emailCheckTokenGeneratedAt}, @@ -20,7 +20,7 @@ INSERT - INTO ACCOUNT(email, email_check_token, email_check_token_generated_at, email_verified, + INTO account(email, email_check_token, email_check_token_generated_at, email_verified, password, withdraw, role, status) VALUES (#{email}, #{emailCheckToken}, #{emailCheckTokenGeneratedAt}, #{emailVerified}, #{password}, #{withdraw}, #{role}, #{status}) diff --git a/src/main/resources/mapper/xml/AccountQueryMapper.xml b/src/main/resources/mapper/xml/AccountQueryMapper.xml index 1e07509..4c8f2a5 100644 --- a/src/main/resources/mapper/xml/AccountQueryMapper.xml +++ b/src/main/resources/mapper/xml/AccountQueryMapper.xml @@ -5,13 +5,13 @@ SELECT * - FROM COMMENT + FROM comment WHERE id = #{id} diff --git a/src/main/resources/mapper/xml/MemberCommandMapper.xml b/src/main/resources/mapper/xml/MemberCommandMapper.xml index 3b4f2ca..6d6b8b6 100644 --- a/src/main/resources/mapper/xml/MemberCommandMapper.xml +++ b/src/main/resources/mapper/xml/MemberCommandMapper.xml @@ -5,12 +5,12 @@ INSERT - INTO MEMBER(nickname, image, status) + INTO member (nickname, image, status) VALUES (#{nickname}, #{image}, #{status}) - UPDATE MEMBER + UPDATE member SET nickname = #{nickname}, image = #{image}, status = #{status} diff --git a/src/main/resources/mapper/xml/TagMapper.xml b/src/main/resources/mapper/xml/TagMapper.xml index cc117b7..d9e48a5 100644 --- a/src/main/resources/mapper/xml/TagMapper.xml +++ b/src/main/resources/mapper/xml/TagMapper.xml @@ -5,13 +5,13 @@ INSERT - INTO TAG(name) + INTO tag (name) VALUES (#{name}) diff --git a/src/main/resources/schema-mysql.sql b/src/main/resources/schema-mysql.sql index ab5865b..8f90f2a 100644 --- a/src/main/resources/schema-mysql.sql +++ b/src/main/resources/schema-mysql.sql @@ -1,3 +1,12 @@ +create table member +( + id bigint not null auto_increment, + nickname varchar(255) not null, + image varchar(255) not null, + status varchar(255) not null, + primary key (id) +) engine=InnoDB; + create table account ( id bigint not null auto_increment, @@ -13,15 +22,14 @@ create table account withdrawal_at timestamp, member_id bigint, status varchar(255) not null, - primary key (id) + primary key (id), + foreign key (member_id) references member (id) ) engine=InnoDB; -create table member +create table tag ( - id bigint not null auto_increment, - nickname varchar(255) not null, - image varchar(255) not null, - status varchar(255) not null, + id bigint not null auto_increment, + name varchar(255) not null, primary key (id) ) engine=InnoDB; @@ -35,7 +43,8 @@ create table article status varchar(255) not null, title varchar(255) not null, member_id bigint, - primary key (id) + primary key (id), + foreign key (member_id) references member (id) ) engine=InnoDB; create table article_likes @@ -43,7 +52,9 @@ create table article_likes id bigint not null auto_increment, article_id bigint, member_id bigint, - primary key (id) + primary key (id), + foreign key (member_id) references member (id), + foreign key (article_id) references article (id) ) engine=InnoDB; create table article_tag @@ -51,7 +62,9 @@ create table article_tag id bigint not null auto_increment, article_id bigint not null, tag_id bigint not null, - primary key (id) + primary key (id), + foreign key (article_id) references article (id), + foreign key (tag_id) references tag (id) ) engine=InnoDB; create table comment @@ -63,7 +76,9 @@ create table comment status varchar(255), article_id bigint, member_id bigint, - primary key (id) + primary key (id), + foreign key (member_id) references member (id), + foreign key (article_id) references article (id) ) engine=InnoDB; create table comment_likes @@ -71,39 +86,14 @@ create table comment_likes id bigint not null auto_increment, comment_id bigint, member_id bigint, - primary key (id) -) engine=InnoDB; - -create table tag -( - id bigint not null auto_increment, - name varchar(255) not null, - primary key (id) + primary key (id), + foreign key (member_id) references member (id), + foreign key (comment_id) references comment (id) ) engine=InnoDB; 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 UK_571gx7oqo5xpmgocegaidlcu9 unique (title); -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;