-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sql
More file actions
75 lines (69 loc) · 2.83 KB
/
setup.sql
File metadata and controls
75 lines (69 loc) · 2.83 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
-- Create Database
CREATE DATABASE IF NOT EXISTS notice_system;
USE notice_system;
-- Users Table
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
role ENUM('super_admin', 'admin', 'teacher', 'student') NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Notices Table
CREATE TABLE IF NOT EXISTS notices (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
created_by INT NOT NULL,
status ENUM(
'pending_admin',
'admin_approved',
'admin_rejected',
'teacher_published',
'teacher_rejected'
) DEFAULT 'pending_admin',
rejection_reason TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(id) ON DELETE CASCADE
);
-- Notice Logs Table (Audit Trail)
CREATE TABLE IF NOT EXISTS notice_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
notice_id INT NOT NULL,
performed_by INT NOT NULL,
role ENUM('super_admin', 'admin', 'teacher', 'student') NOT NULL,
action VARCHAR(50) NOT NULL, -- e.g., 'notice_created', 'admin_approved'
old_status VARCHAR(50),
new_status VARCHAR(50),
details TEXT, -- For rejection reasons or other notes
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (notice_id) REFERENCES notices(id) ON DELETE CASCADE,
FOREIGN KEY (performed_by) REFERENCES users(id) ON DELETE CASCADE
);
-- Notifications Table
CREATE TABLE IF NOT EXISTS notifications (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
message TEXT NOT NULL,
is_read BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);
-- Read Receipts Table (For Students)
CREATE TABLE IF NOT EXISTS read_receipts (
id INT AUTO_INCREMENT PRIMARY KEY,
notice_id INT NOT NULL,
student_id INT NOT NULL,
viewed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (notice_id) REFERENCES notices(id) ON DELETE CASCADE,
FOREIGN KEY (student_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE(notice_id, student_id) -- Ensure one record per student per notice
);
-- Insert Default Users (Password: password123)
-- Hash: $2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi
INSERT INTO users (username, password, role) VALUES
('superadmin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'super_admin'),
('admin', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin'),
('teacher', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'teacher'),
('student', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'student');