-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquerySQL.sql
More file actions
179 lines (165 loc) · 4.31 KB
/
Copy pathquerySQL.sql
File metadata and controls
179 lines (165 loc) · 4.31 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE,
email VARCHAR(100) UNIQUE,
password VARCHAR(255),
reset_token VARCHAR(255),
otp_code VARCHAR(10),
otp_expire DATETIME,
bio TEXT,
location VARCHAR(100),
avatar VARCHAR(255),
created_at TIMESTAMP
);
CREATE TABLE password_resets (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
token VARCHAR(255),
expires_at DATETIME,
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE algorithms (
id INT PRIMARY KEY AUTO_INCREMENT,
alg_key VARCHAR(50),
name VARCHAR(100),
category VARCHAR(50),
description TEXT,
pseudo_code LONGTEXT,
steps JSON,
time_complexity VARCHAR(25),
space_complexity VARCHAR(25),
code_examples JSON,
created_at TIMESTAMP
);
CREATE TABLE questions (
id INT PRIMARY KEY AUTO_INCREMENT,
algorithm_id INT,
question TEXT,
options JSON,
explanation TEXT,
FOREIGN KEY (algorithm_id) REFERENCES algorithms(id)
);
CREATE TABLE user_progress (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
algorithm_id INT,
progress INT,
theory_progress INT DEFAULT 0,
exercises_progress INT DEFAULT 0,
questions_progress INT DEFAULT 0,
last_accessed TIMESTAMP,
status VARCHAR(50),
updated_at TIMESTAMP,
UNIQUE KEY uq_user_progress (user_id, algorithm_id),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (algorithm_id) REFERENCES algorithms(id)
);
CREATE TABLE exercises (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255),
difficulty VARCHAR(50),
category VARCHAR(100),
total_submissions INT,
solved TINYINT(1),
algorithm_id INT,
solution_description TEXT,
created_at TIMESTAMP,
FOREIGN KEY (algorithm_id) REFERENCES algorithms(id)
);
CREATE TABLE problems (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255),
difficulty VARCHAR(50),
category VARCHAR(100),
content_html MEDIUMTEXT,
sample_input TEXT,
sample_output TEXT,
total_submissions INT,
solved INT,
is_public TINYINT(1)
);
CREATE TABLE test_cases (
id INT PRIMARY KEY AUTO_INCREMENT,
problem_id INT,
input_text TEXT,
output_text TEXT,
is_hidden TINYINT(1),
FOREIGN KEY (problem_id) REFERENCES problems(id)
);
CREATE TABLE submissions (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
exercise_id INT,
problem_id INT,
language_id INT,
source_code TEXT,
status VARCHAR(50),
passed_cases INT,
total_cases INT,
time_taken FLOAT,
memory_used FLOAT,
submitted_at TIMESTAMP,
created_at DATETIME,
contest_id INT,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (exercise_id) REFERENCES exercises(id),
FOREIGN KEY (problem_id) REFERENCES problems(id)
);
CREATE TABLE contests (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255),
description TEXT,
start_time DATETIME,
end_time DATETIME,
difficulty VARCHAR(50),
participants INT,
prize VARCHAR(255)
);
CREATE TABLE contest_problems (
contest_id INT,
problem_id INT,
points INT,
PRIMARY KEY (contest_id, problem_id),
FOREIGN KEY (contest_id) REFERENCES contests(id),
FOREIGN KEY (problem_id) REFERENCES problems(id)
);
CREATE TABLE contest_participants (
id INT PRIMARY KEY AUTO_INCREMENT,
contest_id INT,
user_id INT,
registered_at TIMESTAMP,
score INT,
penalty INT,
FOREIGN KEY (contest_id) REFERENCES contests(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE posts (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT,
title VARCHAR(255),
content TEXT,
tags VARCHAR(255),
views INT,
status ENUM('draft','published'),
created_at TIMESTAMP,
image_url VARCHAR(255),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE comments (
id INT PRIMARY KEY AUTO_INCREMENT,
post_id INT,
user_id INT,
content TEXT,
is_accepted TINYINT(1),
created_at TIMESTAMP,
FOREIGN KEY (post_id) REFERENCES posts(id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
CREATE TABLE post_likes (
user_id INT,
post_id INT,
created_at TIMESTAMP,
PRIMARY KEY (user_id, post_id),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (post_id) REFERENCES posts(id)
);