forked from muneebGH/Twitter-Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Twitter-clone-db-script.sql
136 lines (133 loc) · 4.09 KB
/
Twitter-clone-db-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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
DROP DATABASE IF EXISTS Twitter_clone;
CREATE DATABASE Twitter_clone;
USE Twitter_clone;
CREATE TABLE Users
(
user_id int NOT NULL
auto_increment primary key,
username VARCHAR
(50) NOT NULL UNIQUE,
fullname VARCHAR
(50) NOT NULL,
account_Type VARCHAR
(50) NOT NULL,
password VARCHAR
(50) NOT NULL,
description VARCHAR
(256)
);
CREATE TABLE Tweet
(
tweet_id int NOT NULL
auto_increment primary key,
user_id int,
timeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
tweetText VARCHAR
(280) NOT NULL,
foreign key
(user_id) references Users
(user_id));
CREATE TABLE Retweet
(
ret_id int NOT NULL
auto_increment primary key,
user_id int,
tweet_id int,
timeStamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
foreign key
(user_id) references Users
(user_id),
foreign key
(tweet_id) REFERENCES Tweet
(tweet_id));
CREATE TABLE Likes
(
like_id int NOT NULL
auto_increment primary key,
user_id INT,
tweet_id INT,
timeStamp TIMESTAMP
(2) NOT NULL,
foreign key
(user_id) references Users
(user_id),
foreign key
(tweet_id) references Tweet
(tweet_id));
CREATE TABLE HashTag
(
ht_id int NOT NULL
auto_increment primary key,
hashtag VARCHAR
(50)
);
CREATE TABLE HashTagCollection
(
htc_id int NOT NULL
auto_increment primary key,
hashTag_id INT,
tweet_id INT,
foreign key
(hashTag_id) references HashTag
(ht_id),
foreign key
(tweet_id) references Tweet
(tweet_id));
CREATE TABLE Comment
(
com_id int NOT NULL
auto_increment primary key,
user_id int,
tweet_id INT,
text VARCHAR
(280) NOT NULL,
time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
foreign key
(user_id) references Users
(user_id),
foreign key
(tweet_id) references Tweet
(tweet_id));
CREATE TABLE Follower
(
follower_id int NOT NULL
auto_increment primary key,
follower_user_id INT,
following_user_id INT,
foreign key
(follower_user_id) references Users
(user_id),
foreign key
(following_user_id) references Users
(user_id));
CREATE TABLE Conversations
(
c_id int NOT NULL
auto_increment primary key,
user_one INT,
user_two INT,
foreign key
(user_one) references Users
(user_id),
foreign key
(user_two ) references Users
(user_id));
CREATE TABLE Message
(
message_id int NOT NULL
auto_increment primary key,
text VARCHAR
(200) NOT NULL,
time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
sender_id INT,
receiver_id INT,
c_id INT,
foreign key
(sender_id ) references Users
(user_id),
foreign key
(receiver_id) references Users
(user_id),
foreign key
(c_id) references Conversations
(c_id));