-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_schema.sql
More file actions
135 lines (128 loc) · 4.89 KB
/
database_schema.sql
File metadata and controls
135 lines (128 loc) · 4.89 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
-- Create database
CREATE DATABASE IF NOT EXISTS em;
USE em;
-- Create departments table for better organization
CREATE TABLE IF NOT EXISTS departments (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL,
code VARCHAR(10) UNIQUE NOT NULL,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Create event_categories table for better event organization
CREATE TABLE IF NOT EXISTS event_categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL,
description TEXT,
color VARCHAR(7) DEFAULT '#007bff',
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
-- Create admins table
CREATE TABLE IF NOT EXISTS admins (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
first_name VARCHAR(50),
last_name VARCHAR(50),
role ENUM('super_admin', 'admin', 'moderator') DEFAULT 'admin',
is_active BOOLEAN DEFAULT TRUE,
last_login TIMESTAMP NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_username (username),
INDEX idx_email (email),
INDEX idx_role (role)
);
-- Create students table with enhanced fields
CREATE TABLE IF NOT EXISTS students (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id VARCHAR(20) UNIQUE NOT NULL,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL,
phone VARCHAR(15),
department_id INT,
year INT,
semester INT,
date_of_birth DATE,
gender ENUM('male', 'female', 'other'),
address TEXT,
profile_picture VARCHAR(255),
is_active BOOLEAN DEFAULT TRUE,
last_login TIMESTAMP NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (department_id) REFERENCES departments(id) ON DELETE SET NULL,
INDEX idx_student_id (student_id),
INDEX idx_email (email),
INDEX idx_department (department_id),
INDEX idx_year (year)
);
-- Create events table with enhanced fields
CREATE TABLE IF NOT EXISTS events (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(200) NOT NULL,
description TEXT,
category_id INT,
date DATE NOT NULL,
start_time TIME,
end_time TIME,
venue VARCHAR(200) NOT NULL,
max_participants INT DEFAULT 100,
registration_deadline DATETIME,
is_published BOOLEAN DEFAULT FALSE,
is_featured BOOLEAN DEFAULT FALSE,
banner_image VARCHAR(255),
organizer_name VARCHAR(100),
organizer_contact VARCHAR(100),
created_by_admin_id INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (category_id) REFERENCES event_categories(id) ON DELETE SET NULL,
FOREIGN KEY (created_by_admin_id) REFERENCES admins(id) ON DELETE SET NULL,
INDEX idx_date (date),
INDEX idx_category (category_id),
INDEX idx_published (is_published),
INDEX idx_featured (is_featured)
);
-- Create registrations table with enhanced fields
CREATE TABLE IF NOT EXISTS registrations (
id INT AUTO_INCREMENT PRIMARY KEY,
student_id INT NOT NULL,
event_id INT NOT NULL,
registration_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
status ENUM('registered', 'cancelled', 'attended', 'absent') DEFAULT 'registered',
attendance_status ENUM('pending', 'attended', 'absent') DEFAULT 'pending',
cancellation_reason TEXT,
confirmation_code VARCHAR(50) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE,
FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE,
UNIQUE KEY unique_registration (student_id, event_id),
INDEX idx_student (student_id),
INDEX idx_event (event_id),
INDEX idx_status (status),
INDEX idx_attendance (attendance_status)
);
-- Create event_feedback table for collecting feedback
CREATE TABLE IF NOT EXISTS event_feedback (
id INT AUTO_INCREMENT PRIMARY KEY,
event_id INT NOT NULL,
student_id INT NOT NULL,
rating INT CHECK (rating >= 1 AND rating <= 5),
comment TEXT,
is_anonymous BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE,
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE,
UNIQUE KEY unique_feedback (event_id, student_id),
INDEX idx_event (event_id),
INDEX idx_rating (rating)
);