-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDB.sql
More file actions
94 lines (74 loc) · 2.95 KB
/
DB.sql
File metadata and controls
94 lines (74 loc) · 2.95 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
CREATE DATABASE IF NOT EXISTS `janrenovation` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `janrenovation`;
CREATE TABLE `projects` (
`pid` int(11) NOT NULL,
`address` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`borough` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL,
`starttime` datetime DEFAULT NULL,
`endtime` datetime DEFAULT NULL,
`active` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `relations` (
`rid` int(11) NOT NULL,
`uid` int(11) NOT NULL,
`pid` int(11) NOT NULL,
`date` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `sessions` (
`sessionID` varchar(1000) COLLATE utf8mb4_unicode_ci NOT NULL,
`uid` int(11) NOT NULL,
`expiration` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `timesheet` (
`tsid` int(11) NOT NULL,
`uid` int(11) NOT NULL,
`pid` int(11) NOT NULL,
`starttime` datetime DEFAULT NULL,
`endtime` datetime DEFAULT NULL,
`inlocationstart` tinyint(1) NOT NULL,
`inlocationend` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `users` (
`uid` int(11) NOT NULL,
`firstname` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL,
`lastname` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL,
`privilege` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL,
`phone` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`email` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`approved` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `projects`
ADD PRIMARY KEY (`pid`),
ADD UNIQUE KEY `address` (`address`);
ALTER TABLE `relations`
ADD PRIMARY KEY (`rid`),
ADD KEY `uid` (`uid`),
ADD KEY `pid` (`pid`);
ALTER TABLE `sessions`
ADD PRIMARY KEY (`sessionID`(191)),
ADD KEY `uid` (`uid`);
ALTER TABLE `timesheet`
ADD PRIMARY KEY (`tsid`),
ADD KEY `uid` (`uid`),
ADD KEY `pid` (`pid`);
ALTER TABLE `users`
ADD PRIMARY KEY (`uid`),
ADD UNIQUE KEY `email` (`email`);
ALTER TABLE `projects`
MODIFY `pid` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `relations`
MODIFY `rid` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `timesheet`
MODIFY `tsid` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `users`
MODIFY `uid` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `relations`
ADD CONSTRAINT `relations_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `users` (`uid`),
ADD CONSTRAINT `relations_ibfk_2` FOREIGN KEY (`pid`) REFERENCES `projects` (`pid`);
ALTER TABLE `sessions`
ADD CONSTRAINT `sessions_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `users` (`uid`);
ALTER TABLE `timesheet`
ADD CONSTRAINT `timesheet_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `users` (`uid`),
ADD CONSTRAINT `timesheet_ibfk_2` FOREIGN KEY (`pid`) REFERENCES `projects` (`pid`);
COMMIT;