-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.sql
More file actions
89 lines (74 loc) · 2.45 KB
/
db.sql
File metadata and controls
89 lines (74 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# DB 재생성
DROP DATABASE IF EXISTS sbb_2nd;
CREATE DATABASE sbb_2nd;
USE sbb_2nd;
# 질문 테이블 생성
CREATE TABLE question (
id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
create_date DATETIME NOT NULL,
`subject` VARCHAR(200) NOT NULL,
content TEXT NOT NULL
);
# 답변 테이블 생성
CREATE TABLE answer (
id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
create_date DATETIME NOT NULL,
question_id BIGINT UNSIGNED NOT NULL,
content TEXT NOT NULL
);
# 테스트용 질문 2개 생성
INSERT INTO question
SET create_date = NOW(),
`subject` = 'sbb가 무엇인가요?',
content = 'sbb에 대해서 알고 싶습니다.';
INSERT INTO question
SET create_date = NOW(),
`subject` = '스프링부트 모델 질문입니다.',
content = 'id는 자동으로 생성되나요?';
# 사용자 테이블 생성
CREATE TABLE site_user (
id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
username CHAR(100) NOT NULL UNIQUE,
`password` CHAR(100) NOT NULL,
email CHAR(100) NOT NULL UNIQUE
);
# 테스트용 사용자 3명 생성(1명은 관리자)
INSERT INTO site_user
SET username = 'admin',
`password` = '$2a$10$ECLIahn9UgeZxUxmca6HyeYTwOAspolhesV1qXFQNF5zyR20FfmB6',
email = 'admin@test.com';
INSERT INTO site_user
SET username = 'user1',
`password` = '$2a$10$ECLIahn9UgeZxUxmca6HyeYTwOAspolhesV1qXFQNF5zyR20FfmB6',
email = 'user1@test.com';
INSERT INTO site_user
SET username = 'user2',
`password` = '$2a$10$ECLIahn9UgeZxUxmca6HyeYTwOAspolhesV1qXFQNF5zyR20FfmB6',
email = 'user2@test.com';
# 질문 테이블에 site_user_id 칼럼 추가
ALTER TABLE question
ADD COLUMN author_id BIGINT UNSIGNED NOT NULL;
# 기존 질문을 특정 사용자와 연결짓기
UPDATE question
SET author_id = 1;
# 답변 테이블에 site_user_id 칼럼 추가
ALTER TABLE answer
ADD COLUMN author_id BIGINT UNSIGNED NOT NULL;
# 질문 테이블에 modify_date 칼럼 추가
ALTER TABLE question
ADD COLUMN modify_date DATETIME AFTER create_date;
# 답변 테이블에 modify_date 칼럼 추가
ALTER TABLE answer
ADD COLUMN modify_date DATETIME AFTER create_date;
# 질문 추천자(추천내역)
CREATE TABLE question_voter (
id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
question_id BIGINT UNSIGNED NOT NULL,
voter_id BIGINT UNSIGNED NOT NULL
);
# 답변 추천자(추천내역)
CREATE TABLE answer_voter (
id BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
answer_id BIGINT UNSIGNED NOT NULL,
voter_id BIGINT UNSIGNED NOT NULL
);