-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtb-gram.sql
More file actions
42 lines (39 loc) · 1.47 KB
/
tb-gram.sql
File metadata and controls
42 lines (39 loc) · 1.47 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
CREATE TABLE member (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
nick_name VARCHAR(255) NOT NULL UNIQUE,
introduction VARCHAR(255),
deleted_at DATETIME,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
);
CREATE TABLE news_feed (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
member_id BIGINT NOT NULL,
title VARCHAR(255) NOT NULL,
contents TEXT NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
CONSTRAINT fk_news_feed_member FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE
);
CREATE TABLE comment (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
contents TEXT NOT NULL,
member_id BIGINT NOT NULL,
news_feed_id BIGINT NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
CONSTRAINT fk_comment_member FOREIGN KEY (member_id) REFERENCES member(id) ON DELETE CASCADE,
CONSTRAINT fk_comment_news_feed FOREIGN KEY (news_feed_id) REFERENCES news_feed(id) ON DELETE CASCADE
);
CREATE TABLE friends (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
sender_id BIGINT NOT NULL,
receiver_id BIGINT NOT NULL,
status VARCHAR(50) NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
CONSTRAINT fk_friends_sender FOREIGN KEY (sender_id) REFERENCES member(id) ON DELETE CASCADE,
CONSTRAINT fk_friends_receiver FOREIGN KEY (receiver_id) REFERENCES member(id) ON DELETE CASCADE
);