Repository navigation
Expand file tree
/
Copy pathbadger.sql
More file actions
236 lines (220 loc) · 11.4 KB
/
Copy pathbadger.sql
File metadata and controls
236 lines (220 loc) · 11.4 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server version: 10.4.32-MariaDB - mariadb.org binary distribution
-- Server OS: Win64
-- HeidiSQL Version: 12.8.0.6908
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
-- Dumping database structure for badger
CREATE DATABASE IF NOT EXISTS `badger` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;
USE `badger`;
-- Dumping structure for table badger.audit_log
CREATE TABLE IF NOT EXISTS `audit_log` (
`log_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`action` varchar(50) NOT NULL,
`table_name` varchar(50) DEFAULT NULL,
`record_id` int(11) DEFAULT NULL,
`old_values` text DEFAULT NULL,
`new_values` text DEFAULT NULL,
`ip_address` varchar(45) DEFAULT NULL,
`user_agent` text DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`log_id`),
KEY `user_id` (`user_id`),
CONSTRAINT `audit_log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Dumping structure for table badger.blocked_users
CREATE TABLE IF NOT EXISTS `blocked_users` (
`block_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`email` varchar(100) NOT NULL,
`full_name` varchar(100) NOT NULL,
`reason` text NOT NULL,
`blocked_by` int(11) NOT NULL,
`blocked_at` datetime NOT NULL,
`expires_at` datetime DEFAULT NULL,
`is_permanent` tinyint(1) DEFAULT 0,
`is_active` tinyint(1) DEFAULT 1,
PRIMARY KEY (`block_id`),
KEY `user_id` (`user_id`),
KEY `blocked_by` (`blocked_by`),
KEY `idx_email` (`email`),
KEY `idx_is_active` (`is_active`),
CONSTRAINT `blocked_users_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE,
CONSTRAINT `blocked_users_ibfk_2` FOREIGN KEY (`blocked_by`) REFERENCES `users` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Dumping structure for table badger.library_stats
CREATE TABLE IF NOT EXISTS `library_stats` (
`stat_id` int(11) NOT NULL AUTO_INCREMENT,
`stat_date` date NOT NULL,
`visitors_count` int(11) DEFAULT 0,
`studying_count` int(11) DEFAULT 0,
`casual_visitors` int(11) DEFAULT 0,
`active_staff_count` int(11) DEFAULT 0,
`books_borrowed_today` int(11) DEFAULT 0,
`books_returned_today` int(11) DEFAULT 0,
`new_registrations` int(11) DEFAULT 0,
`total_fines_collected` decimal(10,2) DEFAULT 0.00,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`stat_id`),
UNIQUE KEY `stat_date` (`stat_date`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Dumping structure for table badger.notifications
CREATE TABLE IF NOT EXISTS `notifications` (
`notification_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`message` text NOT NULL,
`type` enum('info','success','warning','danger') DEFAULT 'info',
`is_read` tinyint(1) DEFAULT 0,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`notification_id`),
KEY `idx_notifications_user` (`user_id`,`is_read`),
CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Dumping structure for procedure badger.UpdateDailyStats
DELIMITER //
CREATE PROCEDURE `UpdateDailyStats`()
BEGIN
DECLARE v_visitors INT DEFAULT 0;
DECLARE v_studying INT DEFAULT 0;
DECLARE v_casual INT DEFAULT 0;
DECLARE v_staff INT DEFAULT 0;
DECLARE v_borrowed INT DEFAULT 0;
DECLARE v_returned INT DEFAULT 0;
DECLARE v_new_users INT DEFAULT 0;
SET v_visitors = 200 + FLOOR(RAND() * 100);
SET v_studying = 80 + FLOOR(RAND() * 30);
SET v_casual = v_visitors - v_studying;
SET v_staff = (SELECT COUNT(*) FROM users WHERE user_type IN ('staff', 'admin') AND is_active = 1);
SET v_borrowed = FLOOR(RAND() * 40);
SET v_returned = FLOOR(RAND() * 35);
SET v_new_users = FLOOR(RAND() * 5);
INSERT INTO library_stats
(stat_date, visitors_count, studying_count, casual_visitors, active_staff_count,
books_borrowed_today, books_returned_today, new_registrations)
VALUES
(CURDATE(), v_visitors, v_studying, v_casual, v_staff, v_borrowed, v_returned, v_new_users)
ON DUPLICATE KEY UPDATE
visitors_count = v_visitors,
studying_count = v_studying,
casual_visitors = v_casual,
active_staff_count = v_staff,
books_borrowed_today = v_borrowed,
books_returned_today = v_returned,
new_registrations = v_new_users,
updated_at = CURRENT_TIMESTAMP;
END//
DELIMITER ;
-- Dumping structure for table badger.users
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`rfid` varchar(50) DEFAULT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(255) NOT NULL,
`email` varchar(100) NOT NULL,
`full_name` varchar(100) NOT NULL,
`user_type` enum('student','admin','staff') NOT NULL DEFAULT 'student',
`student_id` varchar(20) DEFAULT NULL,
`department` varchar(100) DEFAULT NULL,
`phone` varchar(20) DEFAULT NULL,
`address` text DEFAULT NULL,
`profile_picture` varchar(255) DEFAULT NULL,
`is_active` tinyint(1) DEFAULT 1,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`last_login` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `username` (`username`),
UNIQUE KEY `email` (`email`),
UNIQUE KEY `student_id` (`student_id`),
KEY `idx_users_username` (`username`),
KEY `idx_users_email` (`email`),
KEY `idx_users_type` (`user_type`),
KEY `idx_users_student_id` (`student_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Dumping data for table badger.users
INSERT INTO `users` (`user_id`, `rfid`, `username`, `password`, `email`, `full_name`, `user_type`, `student_id`, `department`, `phone`, `address`, `profile_picture`, `is_active`, `created_at`, `updated_at`, `last_login`) VALUES
(2, NULL, 'admin001', 'password123', 'fac', 'Badger', 'staff', NULL, 'Admin', NULL, NULL, NULL, 1, '2026-03-16 12:08:29', '2026-06-03 04:16:41', NULL),
(4, NULL, 'student001', '123', 'student1', 'Badger', 'student', 'S2024001', 'IT', '555-0101', '', NULL, 1, '2026-03-16 01:19:27', '2026-07-19 07:48:53', NULL),
(7, NULL, 'null2', 'null', 'null2', 'null', 'admin', NULL, NULL, NULL, NULL, NULL, 1, '2026-03-16 09:30:37', '2026-03-20 12:44:53', '2026-03-16 12:56:19'),
(8, NULL, 'playa@badger.edu.ph', 'password123', 'faculty1@badger.edu', 'Prof. Badger', 'staff', NULL, 'Admin', NULL, NULL, NULL, 1, '2026-03-16 12:08:29', '2026-03-20 12:45:13', NULL),
(9, NULL, 'null', 'null', 'null', 'null', 'staff', NULL, 'Engineering', NULL, NULL, NULL, 1, '2026-03-16 12:08:29', '2026-03-20 12:43:53', NULL),
(10, NULL, 'null1', 'null', 'null1', 'null', 'staff', NULL, 'Library Staff', NULL, NULL, NULL, 1, '2026-03-16 12:08:29', '2026-03-20 12:44:14', NULL);
-- Dumping structure for table badger.visitor_logs
CREATE TABLE IF NOT EXISTS `visitor_logs` (
`log_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`email` varchar(100) NOT NULL,
`full_name` varchar(100) NOT NULL,
`user_type` enum('student','faculty','employee','visitor') NOT NULL,
`program_department` varchar(100) DEFAULT NULL,
`reason` varchar(50) NOT NULL,
`reason_details` text DEFAULT NULL,
`entry_time` datetime NOT NULL,
`exit_time` datetime DEFAULT NULL,
`status` enum('active','exited','blocked') DEFAULT 'active',
`approval_status` enum('pending','approved','declined') DEFAULT 'pending',
`approved_by` int(11) DEFAULT NULL,
`approved_at` datetime DEFAULT NULL,
`decline_reason` text DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`log_id`),
KEY `user_id` (`user_id`),
KEY `idx_entry_time` (`entry_time`),
KEY `idx_status` (`status`),
KEY `idx_user_type` (`user_type`),
KEY `idx_reason` (`reason`),
CONSTRAINT `visitor_logs_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=87 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Dumping data for table badger.visitor_logs
INSERT INTO `visitor_logs` (`log_id`, `user_id`, `email`, `full_name`, `user_type`, `program_department`, `reason`, `reason_details`, `entry_time`, `exit_time`, `status`, `approval_status`, `approved_by`, `approved_at`, `decline_reason`, `created_at`) VALUES
(86, 2, 'fac', 'Badger', 'faculty', 'Admin', 'reading', NULL, '2026-08-05 04:58:30', NULL, 'active', 'approved', 1, '2026-08-05 10:58:41', NULL, '2026-08-05 02:58:30');
-- Dumping structure for table badger.visitor_stats
CREATE TABLE IF NOT EXISTS `visitor_stats` (
`stat_id` int(11) NOT NULL AUTO_INCREMENT,
`stat_date` date NOT NULL,
`stat_week` int(11) DEFAULT NULL,
`stat_month` int(11) DEFAULT NULL,
`stat_year` int(11) DEFAULT NULL,
`total_visitors` int(11) DEFAULT 0,
`unique_visitors` int(11) DEFAULT 0,
`students_count` int(11) DEFAULT 0,
`faculty_count` int(11) DEFAULT 0,
`employees_count` int(11) DEFAULT 0,
`reading_count` int(11) DEFAULT 0,
`researching_count` int(11) DEFAULT 0,
`computer_count` int(11) DEFAULT 0,
`meeting_count` int(11) DEFAULT 0,
`other_count` int(11) DEFAULT 0,
`peak_hour` int(11) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`stat_id`),
UNIQUE KEY `unique_date` (`stat_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Dumping structure for trigger badger.after_user_update
SET @OLDTMP_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO';
DELIMITER //
CREATE TRIGGER `after_user_update` AFTER UPDATE ON `users` FOR EACH ROW BEGIN
INSERT INTO audit_log (user_id, action, table_name, record_id, old_values, new_values)
VALUES (NEW.user_id, 'UPDATE', 'users', NEW.user_id,
CONCAT('username:', OLD.username, ', email:', OLD.email, ', active:', OLD.is_active),
CONCAT('username:', NEW.username, ', email:', NEW.email, ', active:', NEW.is_active));
END//
DELIMITER ;
SET SQL_MODE=@OLDTMP_SQL_MODE;
/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;