-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable_creation.py
More file actions
43 lines (38 loc) · 3.1 KB
/
table_creation.py
File metadata and controls
43 lines (38 loc) · 3.1 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
import sqlite3
connection_obj = sqlite3.connect('database.db')
cursor_obj = connection_obj.cursor()
table = """ CREATE Table IF NOT EXISTS user (id INTEGER PRIMARY KEY, name TEXT NOT NULL); """
table2 = """ CREATE Table IF NOT EXISTS post (post_id INTEGER PRIMARY KEY, title TEXT NOT NULL, created_at
TIMESTAMP, user_id INTEGER, FOREIGN KEY(user_id) REFERENCES user(id)); """
table3 = """ CREATE Table IF NOT EXISTS comment (comment_id INTEGER PRIMARY KEY, title TEXT NOT NULL, created_at TIMESTAMP,
user_id INTEGER, parent_comment_id INTEGER REFERENCES comment(comment_id), is_parent BOOLEAN, post_id INTEGER, FOREIGN KEY(user_id) REFERENCES user(id), FOREIGN KEY(post_id) REFERENCES post(post_id)); """
table4 = """ CREATE Table IF NOT EXISTS post_likes_dislikes (id INTEGER PRIMARY KEY, post_id INTEGER, knowledge_begin_date
TIMESTAMP, likes INTEGER, dislikes INTEGER, FOREIGN KEY(post_id) REFERENCES post(post_id)); """
table5 = """ CREATE Table IF NOT EXISTS post_likes (id INTEGER PRIMARY KEY, user_id INTEGER, knowledge_begin_date TIMESTAMP, knowledge_end_date TIMESTAMP, post_id INTEGER, FOREIGN KEY(user_id) REFERENCES user(id), FOREIGN KEY(post_id) REFERENCES post(post_id)); """
table6 = """ CREATE Table IF NOT EXISTS post_dislikes (id INTEGER PRIMARY KEY, user_id INTEGER, knowledge_begin_date TIMESTAMP, knowledge_end_date TIMESTAMP, post_id INTEGER, FOREIGN KEY(user_id) REFERENCES user(id), FOREIGN KEY(post_id) REFERENCES post(post_id)); """
table7 = """ CREATE Table IF NOT EXISTS comment_likes (id INTEGER PRIMARY KEY, user_id INTEGER, knowledge_begin_date TIMESTAMP, knowledge_end_date TIMESTAMP, comment_id INTEGER, FOREIGN KEY(user_id) REFERENCES user(id), FOREIGN KEY(comment_id) REFERENCES comment(comment_id)); """
table8 = """ CREATE Table IF NOT EXISTS comment_dislikes (id INTEGER PRIMARY KEY, user_id INTEGER, knowledge_begin_date TIMESTAMP, knowledge_end_date TIMESTAMP, comment_id INTEGER, FOREIGN KEY(user_id) REFERENCES user(id), FOREIGN KEY(comment_id) REFERENCES comment(comment_id)); """
table9 = """ CREATE Table IF NOT EXISTS comment_likes_dislikes (id INTEGER PRIMARY KEY, comment_id INTEGER, knowledge_begin_date
TIMESTAMP, likes INTEGER, dislikes INTEGER, FOREIGN KEY(comment_id) REFERENCES comment(comment_id)); """
# tabletemp = """ DROP TABLE user; """
# tabletemp1 = """ DROP TABLE post; """
# tabletemp2 = """ DROP TABLE comment; """
# tabletemp3 = """ DROP TABLE post_likes_dislikes; """
# tabletemp4 = """ DROP TABLE post_likes; """
# tabletemp5 = """ DROP TABLE post_dislikes; """
# tabletemp6 = """ DROP TABLE comment_likes; """
# tabletemp7 = """ DROP TABLE comment_dislikes; """
# tabletemp8 = """ DROP TABLE comment_likes_dislikes; """
# table10 = """ALTER TABLE comment ADD FOREIGN KEY(parent_comment_id) REFERENCES comment(comment_id)"""
# tabletemp9 = """PRAGMA foreign_keys = ON;"""
def creation():
cursor_obj.execute(table)
cursor_obj.execute(table2)
cursor_obj.execute(table3)
cursor_obj.execute(table4)
cursor_obj.execute(table5)
cursor_obj.execute(table6)
cursor_obj.execute(table7)
cursor_obj.execute(table8)
cursor_obj.execute(table9)
connection_obj.close()