-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.sql
More file actions
164 lines (149 loc) · 5.19 KB
/
db.sql
File metadata and controls
164 lines (149 loc) · 5.19 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
CREATE DATABASE community_help_center;
USE community_help_center;
-- Users Table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
user_role ENUM('admin', 'member') DEFAULT 'member',
profile_picture_path VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;
-- Discussions Table
CREATE TABLE discussions (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
views INT DEFAULT 0,
status ENUM('active', 'closed') DEFAULT 'active',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB;
-- Categories Table (for organizing questions)
CREATE TABLE categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;
-- Questions Table
CREATE TABLE questions (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
subject VARCHAR(255) NOT NULL,
details TEXT NOT NULL,
category_id INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (category_id) REFERENCES categories(id)
) ENGINE=InnoDB;
-- Answers Table
CREATE TABLE answers (
id INT AUTO_INCREMENT PRIMARY KEY,
question_id INT NOT NULL,
user_id INT NOT NULL,
content TEXT NOT NULL,
likes INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (question_id) REFERENCES questions(id),
FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB;
-- Comments Table
CREATE TABLE comments (
id INT AUTO_INCREMENT PRIMARY KEY,
discussion_id INT NOT NULL,
user_id INT NOT NULL,
content TEXT NOT NULL,
parent_comment_id INT DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (discussion_id) REFERENCES discussions(id),
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (parent_comment_id) REFERENCES comments(id) ON DELETE CASCADE
) ENGINE=InnoDB;
-- Donations Table
CREATE TABLE donations (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
amount DECIMAL(10, 2) NOT NULL,
payment_method VARCHAR(50) DEFAULT NULL,
status ENUM('pending', 'completed', 'failed') DEFAULT 'pending',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB;
-- Files Table
CREATE TABLE files (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
file_path VARCHAR(255) NOT NULL,
file_type VARCHAR(50) NOT NULL,
file_size INT NOT NULL,
uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB;
-- Activity Log Table
CREATE TABLE activity_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
action VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
) ENGINE=InnoDB;
-- Combined Interaction Table for Discussions
CREATE TABLE discussion_interactions (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
discussion_id INT NOT NULL,
interaction_type ENUM('view', 'like', 'share') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (discussion_id) REFERENCES discussions(id)
) ENGINE=InnoDB;
-- Combined Interaction Table for Questions
CREATE TABLE question_interactions (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
question_id INT NOT NULL,
interaction_type ENUM('view', 'like', 'share') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (question_id) REFERENCES questions(id)
) ENGINE=InnoDB;
-- Interactions Table
CREATE TABLE interactions (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
question_id INT NOT NULL,
interaction_type ENUM('view', 'like', 'share') NOT NULL,
content TEXT DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (question_id) REFERENCES questions(id),
UNIQUE KEY unique_interaction (user_id, question_id, interaction_type)
) ENGINE=InnoDB;
-- Anwer likes Table
CREATE TABLE answer_likes (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
answer_id INT NOT NULL,
question_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (answer_id) REFERENCES answers(id),
FOREIGN KEY (question_id) REFERENCES questions(id)
) ENGINE=InnoDB;
-- Comment likes Table
CREATE TABLE comment_likes (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
comment_id INT NOT NULL,
discussion_id INT NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (comment_id) REFERENCES comments(id),
FOREIGN KEY (discussion_id) REFERENCES discussions(id)
) ENGINE=InnoDB;
-- API Cache Table
CREATE TABLE api_cache (
type VARCHAR(50) PRIMARY KEY,
data TEXT,
timestamp TIMESTAMP
);