-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase-initialize.sql
More file actions
146 lines (136 loc) · 4.39 KB
/
database-initialize.sql
File metadata and controls
146 lines (136 loc) · 4.39 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
/*drop database if exists*/
DROP DATABASE [IF EXISTS] studentSite;
/*create database*/
CREATE DATABASE studentSite;
/*create user table*/
CREATE TABLE studentSite.`user` (
`id` BIGINT auto_increment NOT NULL,
`name` varchar(100) NOT NULL,
`surname` varchar(100) NOT NULL,
`username` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(200) NOT NULL,
`grade` varchar(100) NULL,
`phone_number` varchar(100) NULL,
`role` varchar(100) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (`id`)
);
/*create university table*/
CREATE TABLE studentSite.university (
`id` BIGINT auto_increment NOT NULL,
`name` varchar(100) NOT NULL,
`city` varchar(100) NOT NULL,
`rectore_id` BIGINT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `rectore_univeristy_fk`
FOREIGN KEY (rectore_id)
REFERENCES studentSite.`user`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
/*create fakultet table*/
CREATE TABLE studentSite.fakultet (
`id` BIGINT auto_increment NOT NULL,
`name` varchar(100) NOT NULL,
`university_id` BIGINT NOT NULL,
`address` varchar(100) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `university_fakultet_fk`
FOREIGN KEY (university_id)
REFERENCES studentSite.`university`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
/*create departament table*/
CREATE TABLE studentSite.departament (
`id` BIGINT auto_increment NOT NULL,
`name` varchar(100) NOT NULL,
`fakultet_id` BIGINT NOT NULL,
`cheef_id` BIGINT NOT NULL,
`secretary_id` BIGINT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fakultet_departament_fk`
FOREIGN KEY (fakultet_id)
REFERENCES studentSite.`fakultet`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `cheef_departament_fk`
FOREIGN KEY (cheef_id)
REFERENCES studentSite.`user`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `secretary_departament_fk`
FOREIGN KEY (secretary_id)
REFERENCES studentSite.`user`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
/*create dega table*/
CREATE TABLE studentSite.dega (
`id` BIGINT auto_increment NOT NULL,
`name` varchar(100) NOT NULL,
`departament_dega_id` BIGINT NOT NULL,
`secretary_dega_id` BIGINT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `departament_dega_fk`
FOREIGN KEY (departament_dega_id)
REFERENCES studentSite.`departament`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `secretary_dega_fk`
FOREIGN KEY (secretary_dega_id)
REFERENCES studentSite.`user`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
/*create course table*/
CREATE TABLE studentSite.course (
`id` BIGINT auto_increment NOT NULL,
`code` varchar(100) NOT NULL,
`name` varchar(100) NOT NULL,
`dega_id` BIGINT NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `dega_course_fk`
FOREIGN KEY (dega_id)
REFERENCES studentSite.`dega`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
/*create grades table*/
CREATE TABLE studentSite.grades (
`id` BIGINT auto_increment NOT NULL,
`student_id` BIGINT NOT NULL,
`lecture_id` BIGINT NOT NULL,
`course_id` BIGINT NOT NULL,
`grade` varchar(100) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `student_grades_fk`
FOREIGN KEY (student_id)
REFERENCES studentSite.`user`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `lecture_grades_fk`
FOREIGN KEY (lecture_id)
REFERENCES studentSite.`user`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `course_grades_fk`
FOREIGN KEY (course_id)
REFERENCES studentSite.`course`(id)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);