-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sql
56 lines (51 loc) · 1.53 KB
/
script.sql
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
-- Create Users table
CREATE TABLE Users (
user_id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
);
-- Create Posts table
CREATE TABLE Posts (
post_id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES Users(user_id)
);
-- Create Comments table
CREATE TABLE Comments (
comment_id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
post_id INT,
content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES Users(user_id),
FOREIGN KEY (post_id) REFERENCES Posts(post_id)
);
-- Create Likes table
CREATE TABLE Likes (
like_id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
post_id INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES Users(user_id),
FOREIGN KEY (post_id) REFERENCES Posts(post_id)
);
-- Create Shares table
CREATE TABLE Shares (
share_id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
post_id INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES Users(user_id),
FOREIGN KEY (post_id) REFERENCES Posts(post_id)
);
-- Create Follows table
CREATE TABLE Follows (
follower_id INT,
followee_id INT,
PRIMARY KEY (follower_id, followee_id),
FOREIGN KEY (follower_id) REFERENCES Users(user_id),
FOREIGN KEY (followee_id) REFERENCES Users(user_id)
);