-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.sql
58 lines (50 loc) · 1.91 KB
/
project.sql
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
CREATE TABLE users(
id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
firstname VARCHAR(50) NOT NULL,
lastname VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(100) NOT NULL,
picture VARCHAR(50) NOT NULL DEFAULT 'user.jfif',
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
specialty VARCHAR(40) NOT NULL DEFAULT 'Not Specified',
team_id INT UNSIGNED NULL,
FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE
);
INSERT INTO `users` (`firstname`, `lastname`, `email`, `password`) VALUES
('chiagozie', 'okafor', 'collincity111@gmail.com', '554408941e206431e4084b24b3902ffc');
CREATE TABLE admins(
id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
firstname VARCHAR(50) NOT NULL,
lastname VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(100) NOT NULL
);
CREATE TABLE notifications(
id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL,
team_id INT UNSIGNED NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE
);
CREATE TABLE tasks(
id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
description TEXT NULL,
start_date DATE NOT NULL,
end_date DATE NOT NULL
);
CREATE TABLE teams(
id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
name VARCHAR(10) NOT NULL,
document VARCHAR(50) NOT NULL DEFAULT 'Nothing',
disqualify CHAR(1) NOT NULL DEFAULT '0',
winner CHAR(1) NOT NULL DEFAULT '0',
leader_id INT UNSIGNED NULL
);
ALTER TABLE teams add FOREIGN KEY (leader_id) REFERENCES users(id) ON DELETE CASCADE;
CREATE TABLE winners(
id INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
team_id INT UNSIGNED NOT NULL,
task_id INT UNSIGNED NOT NULL,
FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE,
FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE
);