-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_schema.sql
executable file
·61 lines (52 loc) · 1.94 KB
/
database_schema.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
-- host="", # your host, usually localhost
-- user="",
-- passwd="",
-- db="socialnetworkingdb"
-- To connect type in terminal:
-- mysql -h <host> -P 3306 -u <username> -p socialnetworkingdb
SET FOREIGN_KEY_CHECKS = 0;
-- These commands will DELETE ANYTHING IN THE DB. BE CAREFUL.
DROP TABLE IF EXISTS TWEET;
DROP TABLE IF EXISTS USER;
DROP TABLE IF EXISTS HASHTAG;
DROP TABLE IF EXISTS TWEETSENTIMENT;
DROP TABLE IF EXISTS TWEETPOLITICAL;
CREATE TABLE TWEET (
ID VARCHAR(100) PRIMARY KEY,
tweet_text VARCHAR(500) NOT NULL DEFAULT '',
user_id VARCHAR(100) NOT NULL DEFAULT 0,
created_at DATETIME,
retweet_count INT NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES USER(ID) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE USER (
ID VARCHAR(100) PRIMARY KEY,
followers_count INT NOT NULL DEFAULT 0,
friends_count INT NOT NULL DEFAULT 0,
statuses_count INT NOT NULL DEFAULT 0,
screen_name VARCHAR(100) NOT NULL,
name VARCHAR(100) NOT NULL,
verified BOOLEAN NOT NULL DEFAULT FALSE,
location VARCHAR(250)
);
CREATE TABLE HASHTAG (
tweet_id VARCHAR(100) NOT NULL,
hashtag VARCHAR(150) NOT NULL,
FOREIGN KEY (tweet_id) REFERENCES TWEET(ID) ON UPDATE CASCADE ON DELETE CASCADE,
PRIMARY KEY (tweet_id, hashtag)
);
CREATE TABLE TWEETSENTIMENT (
tweet_id VARCHAR(100) PRIMARY KEY,
polarity DECIMAL(6, 5) NOT NULL,
classification VARCHAR(100) NOT NULL,
FOREIGN KEY (tweet_id) REFERENCES TWEET(ID) ON UPDATE CASCADE ON DELETE CASCADE
);
CREATE TABLE TWEETPOLITICAL (
tweet_id VARCHAR(100) PRIMARY KEY,
democrat_prob DECIMAL(6, 5) NOT NULL,
republican_prob DECIMAL(6, 5) NOT NULL,
third_prob DECIMAL(6, 5) NOT NULL,
classification VARCHAR(100) NOT NULL,
FOREIGN KEY (tweet_id) REFERENCES TWEET(ID) ON UPDATE CASCADE ON DELETE CASCADE
);
SET FOREIGN_KEY_CHECKS = 1;