전세계적으로 유명한 SNS 서비스인 인스타그램 설계를 도전해봤다.(단순 사진게시판)
개념적 설계는 Draw.io를 사용했다.
논리적 설계는 EXERD 툴을 사용했다.
물리적 설계는 EXERD 툴을 사용했다.
-- 회원
CREATE TABLE "MY_SCHEMA"."members" (
"member_id" INTEGER NOT NULL DEFAULT AUTO_INCREMENT, -- 회원ID
"name" VARCHAR(50) NULL, -- 이름
"login_id" VARCHAR(255) NULL, -- 로그인ID
"password" VARCHAR(255) NULL, -- 패스워드
"member_content" TEXT NULL, -- 회원설명
"email" VARCHAR(40) NULL, -- 이메일
"zip" INTEGER NULL, -- 우편번호
"address" VARCHAR(255) NULL, -- 기본주소
"address2" VARCHAR(255) NULL, -- 상세주소
"join_at" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 가입일시
"update_at" DATE NULL, -- 수정일시
"out_at" DATE NULL -- 삭제일시
);
-- 회원 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_members"
ON "MY_SCHEMA"."members" ( -- 회원
"member_id" ASC -- 회원ID
);
-- 회원
ALTER TABLE "MY_SCHEMA"."members"
ADD
CONSTRAINT "PK_members" -- 회원 기본키
PRIMARY KEY (
"member_id" -- 회원ID
);
-- 회원
COMMENT ON TABLE "MY_SCHEMA"."members" IS '회원';
-- 회원ID
COMMENT ON COLUMN "MY_SCHEMA"."members"."member_id" IS '회원ID';
-- 이름
COMMENT ON COLUMN "MY_SCHEMA"."members"."name" IS '이름';
-- 로그인ID
COMMENT ON COLUMN "MY_SCHEMA"."members"."login_id" IS '로그인ID';
-- 패스워드
COMMENT ON COLUMN "MY_SCHEMA"."members"."password" IS '패스워드';
-- 회원설명
COMMENT ON COLUMN "MY_SCHEMA"."members"."member_content" IS '회원설명';
-- 이메일
COMMENT ON COLUMN "MY_SCHEMA"."members"."email" IS '이메일';
-- 우편번호
COMMENT ON COLUMN "MY_SCHEMA"."members"."zip" IS '우편번호';
-- 기본주소
COMMENT ON COLUMN "MY_SCHEMA"."members"."address" IS '기본주소';
-- 상세주소
COMMENT ON COLUMN "MY_SCHEMA"."members"."address2" IS '상세주소';
-- 가입일시
COMMENT ON COLUMN "MY_SCHEMA"."members"."join_at" IS '가입일시';
-- 수정일시
COMMENT ON COLUMN "MY_SCHEMA"."members"."update_at" IS '수정일시';
-- 삭제일시
COMMENT ON COLUMN "MY_SCHEMA"."members"."out_at" IS '삭제일시';
-- 회원 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_members" IS '회원 기본키';
-- 회원 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."members"."PK_members" IS '회원 기본키';
-- 팔로우회원
CREATE TABLE "MY_SCHEMA"."follow" (
"member_id" INTEGER NOT NULL, -- 회원ID
"follow_mem_id" INTEGER NULL, -- 팔로우회원ID
"create_at" DATE NULL -- 등록일시
);
-- 팔로우회원 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_follow"
ON "MY_SCHEMA"."follow" ( -- 팔로우회원
"member_id" ASC -- 회원ID
);
-- 팔로우회원
ALTER TABLE "MY_SCHEMA"."follow"
ADD
CONSTRAINT "PK_follow" -- 팔로우회원 기본키
PRIMARY KEY (
"member_id" -- 회원ID
);
-- 팔로우회원
COMMENT ON TABLE "MY_SCHEMA"."follow" IS '팔로우회원';
-- 회원ID
COMMENT ON COLUMN "MY_SCHEMA"."follow"."member_id" IS '회원ID';
-- 팔로우회원ID
COMMENT ON COLUMN "MY_SCHEMA"."follow"."follow_mem_id" IS '팔로우회원ID';
-- 등록일시
COMMENT ON COLUMN "MY_SCHEMA"."follow"."create_at" IS '등록일시';
-- 팔로우회원 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_follow" IS '팔로우회원 기본키';
-- 팔로우회원 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."follow"."PK_follow" IS '팔로우회원 기본키';
-- 게시글
CREATE TABLE "MY_SCHEMA"."posts" (
"post_id" INTEGER NOT NULL, -- 게시글ID
"post_content" TEXT NULL, -- 내용
"like_co" INTEGER NULL, -- 좋아요수
"member_id" INTEGER NULL, -- 작성자ID
"write_at" DATE NULL, -- 작성일시
"update_at" DATE NULL, -- 수정일시
"delete_at" DATE NULL -- 삭제일시
);
-- 게시글 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_posts"
ON "MY_SCHEMA"."posts" ( -- 게시글
"post_id" ASC -- 게시글ID
);
-- 게시글
ALTER TABLE "MY_SCHEMA"."posts"
ADD
CONSTRAINT "PK_posts" -- 게시글 기본키
PRIMARY KEY (
"post_id" -- 게시글ID
);
-- 게시글
COMMENT ON TABLE "MY_SCHEMA"."posts" IS '게시글';
-- 게시글ID
COMMENT ON COLUMN "MY_SCHEMA"."posts"."post_id" IS '게시글ID';
-- 내용
COMMENT ON COLUMN "MY_SCHEMA"."posts"."post_content" IS '내용';
-- 좋아요수
COMMENT ON COLUMN "MY_SCHEMA"."posts"."like_co" IS '좋아요수';
-- 작성자ID
COMMENT ON COLUMN "MY_SCHEMA"."posts"."member_id" IS '작성자ID';
-- 작성일시
COMMENT ON COLUMN "MY_SCHEMA"."posts"."write_at" IS '작성일시';
-- 수정일시
COMMENT ON COLUMN "MY_SCHEMA"."posts"."update_at" IS '수정일시';
-- 삭제일시
COMMENT ON COLUMN "MY_SCHEMA"."posts"."delete_at" IS '삭제일시';
-- 게시글 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_posts" IS '게시글 기본키';
-- 게시글 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."posts"."PK_posts" IS '게시글 기본키';
-- 게시글이미지
CREATE TABLE "MY_SCHEMA"."post_images" (
"image_id" INTEGER NOT NULL, -- 이미지ID
"post_id" INTEGER NULL, -- 게시글ID
"image_knd" INTEGER NULL, -- 이미지종류
"image_link" VARCHAR(255) NULL, -- 이미지링크
"create_at" DATE NULL, -- 등록일시
"update_at" DATE NULL, -- 수정일시
"delete_at" DATE NULL -- 삭제일시
);
-- 게시글이미지 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_post_images"
ON "MY_SCHEMA"."post_images" ( -- 게시글이미지
"image_id" ASC -- 이미지ID
);
-- 게시글이미지
ALTER TABLE "MY_SCHEMA"."post_images"
ADD
CONSTRAINT "PK_post_images" -- 게시글이미지 기본키
PRIMARY KEY (
"image_id" -- 이미지ID
);
-- 게시글이미지
COMMENT ON TABLE "MY_SCHEMA"."post_images" IS '게시글이미지';
-- 이미지ID
COMMENT ON COLUMN "MY_SCHEMA"."post_images"."image_id" IS '이미지ID';
-- 게시글ID
COMMENT ON COLUMN "MY_SCHEMA"."post_images"."post_id" IS '게시글ID';
-- 이미지종류
COMMENT ON COLUMN "MY_SCHEMA"."post_images"."image_knd" IS '이미지종류';
-- 이미지링크
COMMENT ON COLUMN "MY_SCHEMA"."post_images"."image_link" IS '이미지링크';
-- 등록일시
COMMENT ON COLUMN "MY_SCHEMA"."post_images"."create_at" IS '등록일시';
-- 수정일시
COMMENT ON COLUMN "MY_SCHEMA"."post_images"."update_at" IS '수정일시';
-- 삭제일시
COMMENT ON COLUMN "MY_SCHEMA"."post_images"."delete_at" IS '삭제일시';
-- 게시글이미지 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_post_images" IS '게시글이미지 기본키';
-- 게시글이미지 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."post_images"."PK_post_images" IS '게시글이미지 기본키';
-- 댓글
CREATE TABLE "MY_SCHEMA"."comments" (
"comment_id" INTEGER NOT NULL, -- 댓글ID
"post_id" INTEGER NULL, -- 게시글ID
"comment_content" TEXT NULL, -- 댓글내용
"member_id" INTEGER NULL, -- 작성자ID
"write_at" DATE NULL, -- 작성일시
"update_at" DATE NULL, -- 수정일시
"delete_at" DATE NULL -- 삭제일시
);
-- 댓글 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_comments"
ON "MY_SCHEMA"."comments" ( -- 댓글
"comment_id" ASC -- 댓글ID
);
-- 댓글
ALTER TABLE "MY_SCHEMA"."comments"
ADD
CONSTRAINT "PK_comments" -- 댓글 기본키
PRIMARY KEY (
"comment_id" -- 댓글ID
);
-- 댓글
COMMENT ON TABLE "MY_SCHEMA"."comments" IS '댓글';
-- 댓글ID
COMMENT ON COLUMN "MY_SCHEMA"."comments"."comment_id" IS '댓글ID';
-- 게시글ID
COMMENT ON COLUMN "MY_SCHEMA"."comments"."post_id" IS '게시글ID';
-- 댓글내용
COMMENT ON COLUMN "MY_SCHEMA"."comments"."comment_content" IS '댓글내용';
-- 작성자ID
COMMENT ON COLUMN "MY_SCHEMA"."comments"."member_id" IS '작성자ID';
-- 작성일시
COMMENT ON COLUMN "MY_SCHEMA"."comments"."write_at" IS '작성일시';
-- 수정일시
COMMENT ON COLUMN "MY_SCHEMA"."comments"."update_at" IS '수정일시';
-- 삭제일시
COMMENT ON COLUMN "MY_SCHEMA"."comments"."delete_at" IS '삭제일시';
-- 댓글 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_comments" IS '댓글 기본키';
-- 댓글 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."comments"."PK_comments" IS '댓글 기본키';
-- 게시글좋아요
CREATE TABLE "MY_SCHEMA"."post_like" (
"member_id" INTEGER NOT NULL, -- 회원ID
"post_id" INTEGER NOT NULL, -- 게시글ID
"create_at" DATE NULL -- 등록일시
);
-- 게시글좋아요 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_post_like"
ON "MY_SCHEMA"."post_like" ( -- 게시글좋아요
"member_id" ASC, -- 회원ID
"post_id" ASC -- 게시글ID
);
-- 게시글좋아요
ALTER TABLE "MY_SCHEMA"."post_like"
ADD
CONSTRAINT "PK_post_like" -- 게시글좋아요 기본키
PRIMARY KEY (
"member_id", -- 회원ID
"post_id" -- 게시글ID
);
-- 게시글좋아요
COMMENT ON TABLE "MY_SCHEMA"."post_like" IS '게시글좋아요';
-- 회원ID
COMMENT ON COLUMN "MY_SCHEMA"."post_like"."member_id" IS '회원ID';
-- 게시글ID
COMMENT ON COLUMN "MY_SCHEMA"."post_like"."post_id" IS '게시글ID';
-- 등록일시
COMMENT ON COLUMN "MY_SCHEMA"."post_like"."create_at" IS '등록일시';
-- 게시글좋아요 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_post_like" IS '게시글좋아요 기본키';
-- 게시글좋아요 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."post_like"."PK_post_like" IS '게시글좋아요 기본키';
-- 댓글좋아요
CREATE TABLE "MY_SCHEMA"."comment_like" (
"member_id" INTEGER NOT NULL, -- 회원ID
"comment_id" INTEGER NOT NULL, -- 댓글ID
"create_at" DATE NULL -- 등록일시
);
-- 댓글좋아요 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_comment_like"
ON "MY_SCHEMA"."comment_like" ( -- 댓글좋아요
"member_id" ASC, -- 회원ID
"comment_id" ASC -- 댓글ID
);
-- 댓글좋아요
ALTER TABLE "MY_SCHEMA"."comment_like"
ADD
CONSTRAINT "PK_comment_like" -- 댓글좋아요 기본키
PRIMARY KEY (
"member_id", -- 회원ID
"comment_id" -- 댓글ID
);
-- 댓글좋아요
COMMENT ON TABLE "MY_SCHEMA"."comment_like" IS '댓글좋아요';
-- 회원ID
COMMENT ON COLUMN "MY_SCHEMA"."comment_like"."member_id" IS '회원ID';
-- 댓글ID
COMMENT ON COLUMN "MY_SCHEMA"."comment_like"."comment_id" IS '댓글ID';
-- 등록일시
COMMENT ON COLUMN "MY_SCHEMA"."comment_like"."create_at" IS '등록일시';
-- 댓글좋아요 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_comment_like" IS '댓글좋아요 기본키';
-- 댓글좋아요 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."comment_like"."PK_comment_like" IS '댓글좋아요 기본키';
-- 댓글답변
CREATE TABLE "MY_SCHEMA"."reply" (
"reply_id" INTEGER NOT NULL, -- 답변ID
"comment_id" INTEGER NULL, -- 댓글ID
"reply_content" TEXT NULL, -- 답변내용
"member_id" INTEGER NULL, -- 작성자ID
"write_at" DATE NULL, -- 작성일시
"update_at" DATE NULL, -- 수정일시
"delete_at" DATE NULL -- 삭제일시
);
-- 댓글답변 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_reply"
ON "MY_SCHEMA"."reply" ( -- 댓글답변
"reply_id" ASC -- 답변ID
);
-- 댓글답변
ALTER TABLE "MY_SCHEMA"."reply"
ADD
CONSTRAINT "PK_reply" -- 댓글답변 기본키
PRIMARY KEY (
"reply_id" -- 답변ID
);
-- 댓글답변
COMMENT ON TABLE "MY_SCHEMA"."reply" IS '댓글답변';
-- 답변ID
COMMENT ON COLUMN "MY_SCHEMA"."reply"."reply_id" IS '답변ID';
-- 댓글ID
COMMENT ON COLUMN "MY_SCHEMA"."reply"."comment_id" IS '댓글ID';
-- 답변내용
COMMENT ON COLUMN "MY_SCHEMA"."reply"."reply_content" IS '답변내용';
-- 작성자ID
COMMENT ON COLUMN "MY_SCHEMA"."reply"."member_id" IS '작성자ID';
-- 작성일시
COMMENT ON COLUMN "MY_SCHEMA"."reply"."write_at" IS '작성일시';
-- 수정일시
COMMENT ON COLUMN "MY_SCHEMA"."reply"."update_at" IS '수정일시';
-- 삭제일시
COMMENT ON COLUMN "MY_SCHEMA"."reply"."delete_at" IS '삭제일시';
-- 댓글답변 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_reply" IS '댓글답변 기본키';
-- 댓글답변 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."reply"."PK_reply" IS '댓글답변 기본키';
-- 답변좋아요
CREATE TABLE "MY_SCHEMA"."reply_like" (
"member_id" INTEGER NOT NULL, -- 회원ID
"reply_id" INTEGER NOT NULL, -- 답변ID
"create_at" DATE NULL -- 등록일시
);
-- 답변좋아요 기본키
CREATE UNIQUE INDEX "MY_SCHEMA"."PK_reply_like"
ON "MY_SCHEMA"."reply_like" ( -- 답변좋아요
"member_id" ASC, -- 회원ID
"reply_id" ASC -- 답변ID
);
-- 답변좋아요
ALTER TABLE "MY_SCHEMA"."reply_like"
ADD
CONSTRAINT "PK_reply_like" -- 답변좋아요 기본키
PRIMARY KEY (
"member_id", -- 회원ID
"reply_id" -- 답변ID
);
-- 답변좋아요
COMMENT ON TABLE "MY_SCHEMA"."reply_like" IS '답변좋아요';
-- 회원ID
COMMENT ON COLUMN "MY_SCHEMA"."reply_like"."member_id" IS '회원ID';
-- 답변ID
COMMENT ON COLUMN "MY_SCHEMA"."reply_like"."reply_id" IS '답변ID';
-- 등록일시
COMMENT ON COLUMN "MY_SCHEMA"."reply_like"."create_at" IS '등록일시';
-- 답변좋아요 기본키
COMMENT ON INDEX "MY_SCHEMA"."PK_reply_like" IS '답변좋아요 기본키';
-- 답변좋아요 기본키
COMMENT ON CONSTRAINT "MY_SCHEMA"."reply_like"."PK_reply_like" IS '답변좋아요 기본키';
-- 팔로우회원
ALTER TABLE "MY_SCHEMA"."follow"
ADD
CONSTRAINT "FK_members_TO_follow" -- 회원 -> 팔로우회원
FOREIGN KEY (
"member_id" -- 회원ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 팔로우회원
COMMENT ON CONSTRAINT "MY_SCHEMA"."follow"."FK_members_TO_follow" IS '회원 -> 팔로우회원';
-- 팔로우회원
ALTER TABLE "MY_SCHEMA"."follow"
ADD
CONSTRAINT "FK_members_TO_follow2" -- 회원 -> 팔로우회원2
FOREIGN KEY (
"follow_mem_id" -- 팔로우회원ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 팔로우회원2
COMMENT ON CONSTRAINT "MY_SCHEMA"."follow"."FK_members_TO_follow2" IS '회원 -> 팔로우회원2';
-- 게시글
ALTER TABLE "MY_SCHEMA"."posts"
ADD
CONSTRAINT "FK_members_TO_posts" -- 회원 -> 게시글
FOREIGN KEY (
"member_id" -- 작성자ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 게시글
COMMENT ON CONSTRAINT "MY_SCHEMA"."posts"."FK_members_TO_posts" IS '회원 -> 게시글';
-- 게시글이미지
ALTER TABLE "MY_SCHEMA"."post_images"
ADD
CONSTRAINT "FK_posts_TO_post_images" -- 게시글 -> 게시글이미지
FOREIGN KEY (
"post_id" -- 게시글ID
)
REFERENCES "MY_SCHEMA"."posts" ( -- 게시글
"post_id" -- 게시글ID
);
-- 게시글 -> 게시글이미지
COMMENT ON CONSTRAINT "MY_SCHEMA"."post_images"."FK_posts_TO_post_images" IS '게시글 -> 게시글이미지';
-- 댓글
ALTER TABLE "MY_SCHEMA"."comments"
ADD
CONSTRAINT "FK_members_TO_comments" -- 회원 -> 댓글
FOREIGN KEY (
"member_id" -- 작성자ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 댓글
COMMENT ON CONSTRAINT "MY_SCHEMA"."comments"."FK_members_TO_comments" IS '회원 -> 댓글';
-- 댓글
ALTER TABLE "MY_SCHEMA"."comments"
ADD
CONSTRAINT "FK_posts_TO_comments" -- 게시글 -> 댓글
FOREIGN KEY (
"post_id" -- 게시글ID
)
REFERENCES "MY_SCHEMA"."posts" ( -- 게시글
"post_id" -- 게시글ID
);
-- 게시글 -> 댓글
COMMENT ON CONSTRAINT "MY_SCHEMA"."comments"."FK_posts_TO_comments" IS '게시글 -> 댓글';
-- 게시글좋아요
ALTER TABLE "MY_SCHEMA"."post_like"
ADD
CONSTRAINT "FK_members_TO_post_like" -- 회원 -> 게시글좋아요
FOREIGN KEY (
"member_id" -- 회원ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 게시글좋아요
COMMENT ON CONSTRAINT "MY_SCHEMA"."post_like"."FK_members_TO_post_like" IS '회원 -> 게시글좋아요';
-- 게시글좋아요
ALTER TABLE "MY_SCHEMA"."post_like"
ADD
CONSTRAINT "FK_posts_TO_post_like" -- 게시글 -> 게시글좋아요
FOREIGN KEY (
"post_id" -- 게시글ID
)
REFERENCES "MY_SCHEMA"."posts" ( -- 게시글
"post_id" -- 게시글ID
);
-- 게시글 -> 게시글좋아요
COMMENT ON CONSTRAINT "MY_SCHEMA"."post_like"."FK_posts_TO_post_like" IS '게시글 -> 게시글좋아요';
-- 댓글좋아요
ALTER TABLE "MY_SCHEMA"."comment_like"
ADD
CONSTRAINT "FK_members_TO_comment_like" -- 회원 -> 댓글좋아요
FOREIGN KEY (
"member_id" -- 회원ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 댓글좋아요
COMMENT ON CONSTRAINT "MY_SCHEMA"."comment_like"."FK_members_TO_comment_like" IS '회원 -> 댓글좋아요';
-- 댓글좋아요
ALTER TABLE "MY_SCHEMA"."comment_like"
ADD
CONSTRAINT "FK_comments_TO_comment_like" -- 댓글 -> 댓글좋아요
FOREIGN KEY (
"comment_id" -- 댓글ID
)
REFERENCES "MY_SCHEMA"."comments" ( -- 댓글
"comment_id" -- 댓글ID
);
-- 댓글 -> 댓글좋아요
COMMENT ON CONSTRAINT "MY_SCHEMA"."comment_like"."FK_comments_TO_comment_like" IS '댓글 -> 댓글좋아요';
-- 댓글답변
ALTER TABLE "MY_SCHEMA"."reply"
ADD
CONSTRAINT "FK_comments_TO_reply" -- 댓글 -> 댓글답변
FOREIGN KEY (
"comment_id" -- 댓글ID
)
REFERENCES "MY_SCHEMA"."comments" ( -- 댓글
"comment_id" -- 댓글ID
);
-- 댓글 -> 댓글답변
COMMENT ON CONSTRAINT "MY_SCHEMA"."reply"."FK_comments_TO_reply" IS '댓글 -> 댓글답변';
-- 댓글답변
ALTER TABLE "MY_SCHEMA"."reply"
ADD
CONSTRAINT "FK_members_TO_reply" -- 회원 -> 댓글답변
FOREIGN KEY (
"member_id" -- 작성자ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 댓글답변
COMMENT ON CONSTRAINT "MY_SCHEMA"."reply"."FK_members_TO_reply" IS '회원 -> 댓글답변';
-- 답변좋아요
ALTER TABLE "MY_SCHEMA"."reply_like"
ADD
CONSTRAINT "FK_members_TO_reply_like" -- 회원 -> 답변좋아요
FOREIGN KEY (
"member_id" -- 회원ID
)
REFERENCES "MY_SCHEMA"."members" ( -- 회원
"member_id" -- 회원ID
);
-- 회원 -> 답변좋아요
COMMENT ON CONSTRAINT "MY_SCHEMA"."reply_like"."FK_members_TO_reply_like" IS '회원 -> 답변좋아요';
-- 답변좋아요
ALTER TABLE "MY_SCHEMA"."reply_like"
ADD
CONSTRAINT "FK_reply_TO_reply_like" -- 댓글답변 -> 답변좋아요
FOREIGN KEY (
"reply_id" -- 답변ID
)
REFERENCES "MY_SCHEMA"."reply" ( -- 댓글답변
"reply_id" -- 답변ID
);
-- 댓글답변 -> 답변좋아요
COMMENT ON CONSTRAINT "MY_SCHEMA"."reply_like"."FK_reply_TO_reply_like" IS '댓글답변 -> 답변좋아요';
-- 찜수 증가 트리거
DELIMITER $$
CREATE TRIGGER tg_insert_update_like_co
AFTER INSERT ON post_like
FOR EACH ROW
BEGIN
DECLARE v_id INT;
DECLARE v_co INT DEFAULT 1;
SET v_id = new.post_id;
UPDATE post
SET like_co = like_co + v_co
WHERE post_id = v_id
END $$
DELIMITER ;
-- 찜수 하락 트리거
DELIMITER $$
CREATE TRIGGER tg_insert_update_like_co
BEFORE DELETE ON post_like
FOR EACH ROW
BEGIN
DECLARE v_id INT;
DECLARE v_co INT DEFAULT 1;
SET v_id = new.post_id;
UPDATE post
SET like_co = like_co - v_co
WHERE post_id = v_id
END $$
DELIMITER ;