Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: draft table 위치를 이동 #44

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 110 additions & 5 deletions data/db/migration/entity/V1.00.0.0__draft_table_design.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,116 @@
-- 작가 및 유저
CREATE TABLE users
CREATE TABLE member
(
id BIGINT NOT NULL AUTO_INCREMENT,
email VARCHAR(255) NOT NULL,
type_cd TINYINT NOT NULL,
description JSON NOT NULL DEFAULT (JSON_OBJECT()),
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE (email)
);

-- 아티클 마스터
CREATE TABLE article_mst
(
id BIGINT NOT NULL AUTO_INCREMENT,
member_id BIGINT NOT NULL,
main_image_url VARCHAR(255) NOT NULL,
title VARCHAR(255) NOT NULL,
category_cd TINYINT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id)
);

-- 아티클 인포
CREATE TABLE article_ifo
(
article_mst_id BIGINT NOT NULL,
content TEXT NOT NULL,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (article_mst_id)
);

-- 학습지
CREATE TABLE workbook
(
id BIGINT NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
main_image_url VARCHAR(255) NOT NULL,
category_cd TINYINT NOT NULL,
description VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id)
);

-- 작가-학습지 매핑테이블(다대다)
CREATE TABLE mapping_member_workbook
(
member_id BIGINT NOT NULL,
workbook_id BIGINT NOT NULL,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (workbook_id, member_id)
);

-- 학습지-아티클 매핑테이블(다대다)
CREATE TABLE mapping_workbook_article
(
workbook_id BIGINT NOT NULL,
article_id BIGINT NOT NULL,
day_col int NOT NULL,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (workbook_id, article_id)
);

-- 문제, 정답, 해설(메타데이터)
CREATE TABLE problem
(
id BIGINT NOT NULL AUTO_INCREMENT,
article_id BIGINT NOT NULL,
title VARCHAR(255) NOT NULL,
contents JSON NOT NULL,
answer VARCHAR(255) NOT NULL,
explanation VARCHAR(255) NOT NULL,
creator_id BIGINT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id)
);

-- 풀이 히스토리
CREATE TABLE submit_history
(
id BIGINT NOT NULL AUTO_INCREMENT,
email VARCHAR(255) NOT NULL,
type_cd TINYINT NOT NULL,
problem_id BIGINT NOT NULL,
member_id BIGINT NOT NULL,
submit_ans VARCHAR(255) NOT NULL,
is_solved bit(1) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id)
);

-- 구독
CREATE TABLE subscription
(
id BIGINT NOT NULL AUTO_INCREMENT,
member_id BIGINT NOT NULL,
target_member_id BIGINT NULL,
target_workbook_id BIGINT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP NULL DEFAULT NULL,
PRIMARY KEY (id),
UNIQUE (email)
);
UNIQUE (target_member_id, member_id),
UNIQUE (target_workbook_id, member_id)
);

-- [인덱스 추가] --
-- problem_idx1: problem 테이블에서 article_id 기반으로 문제 조회시 사용
CREATE INDEX problem_idx1 ON problem (article_id)

-- article_mst_idx1: 작가가 작성한 아티클 조회시 사용
CREATE INDEX article_mst_idx1 ON article_mst (member_id)
7 changes: 0 additions & 7 deletions data/db/migration/entity/V1.00.0.0__init_foo_table.sql

This file was deleted.

This file was deleted.

Loading