
위 디자인 pigma를 통한 화면 설계서이다.
제목,
프로필 사진,
ID,
작성 날짜,
좋아요 기능,
사진(생략 가능),
힐링 메시지(텍스트),
댓글
등의 기능이 있다.
힐링 메시지의 텍스트에는 "마크다운 문법"을 지원할 계획이다.
-- healingmessage 테이블 생성
CREATE TABLE healingmessage (
messageId BIGINT AUTO_INCREMENT PRIMARY KEY,
userNumber BIGINT NOT NULL,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
imagePath VARCHAR(255) NULL,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
likes INT DEFAULT 0,
FOREIGN KEY (userNumber) REFERENCES member(userNumber) ON DELETE CASCADE
);
-- healingmessage_comment 테이블 생성
CREATE TABLE healingmessage_comment (
commentId BIGINT AUTO_INCREMENT PRIMARY KEY,
messageId BIGINT NOT NULL,
userNumber BIGINT NOT NULL,
content TEXT NOT NULL,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (messageId) REFERENCES healingmessage(messageId) ON DELETE CASCADE,
FOREIGN KEY (userNumber) REFERENCES member(userNumber) ON DELETE CASCADE
);
-- healingmessage_like 테이블 생성
CREATE TABLE healingmessage_like (
likeId BIGINT AUTO_INCREMENT PRIMARY KEY,
messageId BIGINT NOT NULL,
userNumber BIGINT NOT NULL,
createdDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (messageId) REFERENCES healingmessage(messageId) ON DELETE CASCADE,
FOREIGN KEY (userNumber) REFERENCES member(userNumber) ON DELETE CASCADE
);
여기서
ON DELETE CASCADE
외래키 제약 조건에 사용되는 옵션으로, 참조된 행이 삭제될 때 참조하고 있는 행도 자동으로 삭제되도록 설정하는 규칙이다.
여기서는 게시글을 작성한 작성자가 delete되면 해당 작성자가 작성한 게시글이 모두 delete 되는 것이다.
해당 명령어는 위 모든 테이블의 마지막에 동일하게 설정되어 있다.
Table member {
userNumber BIGINT [pk] // 회원 고유 번호
.
.
.
}
Table healingmessage {
messageId BIGINT [pk, increment] // 게시물 고유 ID
userNumber BIGINT [not null, ref: > member.userNumber] // 게시자 고유 번호
title VARCHAR(255) [not null] // 게시물 제목
content TEXT [not null] // 게시물 본문
imagePath VARCHAR(255) // 게시물 이미지 경로
createdDate TIMESTAMP [default: `CURRENT_TIMESTAMP`] // 작성 날짜
likes INT [default: 0] // 좋아요 수
}
Table healingmessage_comment {
commentId BIGINT [pk, increment] // 댓글 고유 ID
messageId BIGINT [not null, ref: > healingmessage.messageId] // 댓글이 달린 게시물 ID
userNumber BIGINT [not null, ref: > member.userNumber] // 댓글 작성자 ID
content TEXT [not null] // 댓글 내용
createdDate TIMESTAMP [default: `CURRENT_TIMESTAMP`] // 작성 날짜
}
Table healingmessage_like {
likeId BIGINT [pk, increment] // 좋아요 고유 ID
messageId BIGINT [not null, ref: > healingmessage.messageId] // 좋아요가 눌린 게시물 ID
userNumber BIGINT [not null, ref: > member.userNumber] // 좋아요를 누른 사용자 ID
createdDate TIMESTAMP [default: `CURRENT_TIMESTAMP`] // 좋아요 날짜
}
