-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.sql
More file actions
50 lines (39 loc) · 1.61 KB
/
db.sql
File metadata and controls
50 lines (39 loc) · 1.61 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
CREATE DATABASE IF NOT EXISTS event_manager;
USE event_manager;
CREATE TABLE IF NOT EXISTS `candidates` (
`uid` INT(11) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(100) NOT NULL,
`age` INT(3) NOT NULL,
`phone` VARCHAR(15) NOT NULL,
`gender` VARCHAR(10) NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `points_log` (
`log_id` INT(11) NOT NULL AUTO_INCREMENT,
`candidate_uid` INT(11) NOT NULL,
`points` INT(11) NOT NULL,
`reason` VARCHAR(255) NOT NULL,
`admin_username` VARCHAR(50) NULL DEFAULT NULL,
`awarded_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`log_id`),
FOREIGN KEY (`candidate_uid`) REFERENCES `candidates`(`uid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `attendance` (
`attendance_id` INT(11) NOT NULL AUTO_INCREMENT,
`candidate_uid` INT(11) NOT NULL,
`event_day` INT(1) NOT NULL,
`attended_at` DATE NOT NULL,
PRIMARY KEY (`attendance_id`),
FOREIGN KEY (`candidate_uid`) REFERENCES `candidates`(`uid`) ON DELETE CASCADE,
-- --- Add this line ---
UNIQUE KEY `unique_attendance_per_day` (`candidate_uid`, `event_day`)
-- --- End Add ---
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `admins` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`username` VARCHAR(50) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;