-
Notifications
You must be signed in to change notification settings - Fork 0
/
databaseSetup.sql
349 lines (286 loc) · 11 KB
/
databaseSetup.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Sep 07, 2019 at 06:10 PM
-- Server version: 5.7.26
-- PHP Version: 7.2.18
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `nastavnicki_predlozi`
--
-- --------------------------------------------------------
--
-- Table structure for table `admins`
--
DROP TABLE IF EXISTS `admins`;
CREATE TABLE IF NOT EXISTS `admins` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `admins_ibfk_1` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `admins`
--
INSERT INTO `admins` (`id`, `user_id`) VALUES
(2, 135);
-- --------------------------------------------------------
--
-- Table structure for table `departments`
--
DROP TABLE IF EXISTS `departments`;
CREATE TABLE IF NOT EXISTS `departments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `departments`
--
INSERT INTO `departments` (`id`, `name`) VALUES
(4, 'Biologija i ekologija'),
(5, 'Fizika'),
(6, 'Geografija'),
(7, 'Hemija'),
(8, 'Matematika'),
(9, 'Računarske nauke'),
(10, 'Uprava');
-- --------------------------------------------------------
--
-- Table structure for table `feeds`
--
DROP TABLE IF EXISTS `feeds`;
CREATE TABLE IF NOT EXISTS `feeds` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`title` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`body` varchar(1000) COLLATE utf8_unicode_ci NOT NULL,
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=283 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `feeds`
--
INSERT INTO `feeds` (`id`, `user_id`, `title`, `body`, `createdAt`) VALUES
(264, 160, 'Naslov - predlog 4', 'Predlog 4', '2019-08-10 14:35:24'),
(265, 160, 'Naslov - predlog 5', 'Predlog 5', '2019-08-10 14:36:21'),
(266, 160, 'Naslov - predlog 6', 'Predlog 6', '2019-08-10 14:37:34'),
(267, 160, 'Naslov - predlog 7', 'Predlog 7', '2019-08-10 14:41:38'),
(270, 162, 'Naslov - predlog 8', 'Predlog 8', '2019-08-25 11:43:27'),
(271, 162, 'Naslov - predlog 9', 'Predlog 9', '2019-08-25 11:44:35'),
(272, 162, 'Naslov - predlog 10', 'Predlog 10', '2019-08-25 11:45:18'),
(273, 161, 'Naslov - predlog 11', 'Predlog 11', '2019-08-26 16:15:23'),
(281, 135, 'Novi naslov', 'Novi predlog', '2019-09-07 16:34:55'),
(282, 166, 'Novi naslov', 'Novi predlog', '2019-09-07 17:22:21');
--
-- Triggers `feeds`
--
DROP TRIGGER IF EXISTS `on_feed_created_like`;
DELIMITER $$
CREATE TRIGGER `on_feed_created_like` AFTER INSERT ON `feeds` FOR EACH ROW BEGIN
INSERT INTO feed_likes(feed_id) VALUES (NEW.id);
END
$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Table structure for table `feed_likes`
--
DROP TABLE IF EXISTS `feed_likes`;
CREATE TABLE IF NOT EXISTS `feed_likes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`feed_id` int(11) NOT NULL,
`counter` int(11) DEFAULT '0',
PRIMARY KEY (`id`),
KEY `feed_id` (`feed_id`)
) ENGINE=InnoDB AUTO_INCREMENT=261 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `feed_likes`
--
INSERT INTO `feed_likes` (`id`, `feed_id`, `counter`) VALUES
(242, 264, 0),
(243, 265, 0),
(244, 266, 0),
(245, 267, 0),
(248, 270, 0),
(249, 271, 0),
(250, 272, 2),
(251, 273, 2),
(259, 281, 0),
(260, 282, 0);
-- --------------------------------------------------------
--
-- Table structure for table `feed_likes_user_id`
--
DROP TABLE IF EXISTS `feed_likes_user_id`;
CREATE TABLE IF NOT EXISTS `feed_likes_user_id` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`feed_id` int(11) DEFAULT NULL,
`user_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
KEY `feed_id` (`feed_id`,`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `feed_likes_user_id`
--
INSERT INTO `feed_likes_user_id` (`id`, `feed_id`, `user_id`) VALUES
(18, 272, 135),
(20, 272, 166),
(17, 273, 135),
(19, 273, 166);
--
-- Triggers `feed_likes_user_id`
--
DROP TRIGGER IF EXISTS `on_user_add_like`;
DELIMITER $$
CREATE TRIGGER `on_user_add_like` AFTER INSERT ON `feed_likes_user_id` FOR EACH ROW BEGIN
UPDATE `feed_likes`
SET `feed_likes`.`counter`=`feed_likes`.`counter`+1
WHERE `feed_likes`.`feed_id` = NEW.`feed_id`;
END
$$
DELIMITER ;
DROP TRIGGER IF EXISTS `on_user_remove_like`;
DELIMITER $$
CREATE TRIGGER `on_user_remove_like` AFTER DELETE ON `feed_likes_user_id` FOR EACH ROW BEGIN
UPDATE `feed_likes`
SET `feed_likes`.`counter`=`feed_likes`.`counter`-1
WHERE `feed_likes`.`feed_id` = OLD.`feed_id`;
END
$$
DELIMITER ;
-- --------------------------------------------------------
--
-- Table structure for table `profile_images`
--
DROP TABLE IF EXISTS `profile_images`;
CREATE TABLE IF NOT EXISTS `profile_images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`path` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `profile_images`
--
INSERT INTO `profile_images` (`id`, `user_id`, `path`) VALUES
(30, 160, 'profile_1.png'),
(31, 161, 'profile_2.png'),
(32, 162, 'profile_3.png'),
(33, 163, 'profile_4.png'),
(37, 165, 'profile_5.png'),
(38, 166, 'profile_6.png'),
(56, 135, 'profile_7.png'),
(89, 195, 'profile_8.png');
-- --------------------------------------------------------
--
-- Table structure for table `remembered_logins`
--
DROP TABLE IF EXISTS `remembered_logins`;
CREATE TABLE IF NOT EXISTS `remembered_logins` (
`token_hash` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(11) NOT NULL,
`expires_at` datetime NOT NULL,
PRIMARY KEY (`token_hash`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`fullName` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password_hash` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password_reset_hash` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
`password_reset_expires_at` datetime DEFAULT NULL,
`activation_hash` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
`is_active` tinyint(1) NOT NULL DEFAULT '0',
`department_id` int(11) NOT NULL,
`cabinetName` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`,`password_reset_hash`),
KEY `faculty_id` (`department_id`)
) ENGINE=InnoDB AUTO_INCREMENT=230 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `users`
--
INSERT INTO `users` (`id`, `name`, `fullName`, `email`, `password_hash`, `password_reset_hash`, `password_reset_expires_at`, `activation_hash`, `is_active`, `department_id`, `cabinetName`, `createdAt`) VALUES
(135, 'Admin', 'Admin Adminić', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 6, 'adminCabinet', '2019-08-08 11:40:22'),
(160, 'Milan', 'Milan Milanović', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 6, '12', '2019-08-14 14:24:12'),
(161, 'Snežana', 'Snežana Snežanić', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 8, '13', '2019-08-06 14:43:45'),
(162, 'Bojan', 'Bojan Bojanić', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 8, '111', '2019-08-07 22:00:00'),
(163, 'Marko', 'Marko Marković', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 9, '123', '2019-08-26 16:17:40'),
(165, 'Milena', 'Milena Milenović', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 7, '111', '2019-08-26 16:18:08'),
(166, 'Mila', 'Mila Milanović', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 7, '11', '2019-08-26 16:20:07'),
(195, 'Marija', 'Marija Marijanović', '[email protected]', '$2y$10$zTSyJC0/Cz1RMjtDq9tbfe4TqfxgPN0PAqETfqsS7fCCAZIzisnB.', NULL, NULL, NULL, 1, 7, '111', '2019-09-04 11:05:53');
--
-- Triggers `users`
--
DROP TRIGGER IF EXISTS `on_user_deleted`;
DELIMITER $$
CREATE TRIGGER `on_user_deleted` BEFORE DELETE ON `users` FOR EACH ROW BEGIN
DELETE from `feed_likes_user_id`
WHERE `feed_likes_user_id`.`user_id` = OLD.`id`;
END
$$
DELIMITER ;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `admins`
--
ALTER TABLE `admins`
ADD CONSTRAINT `admins_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `feeds`
--
ALTER TABLE `feeds`
ADD CONSTRAINT `feeds_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `feed_likes`
--
ALTER TABLE `feed_likes`
ADD CONSTRAINT `feed_likes_ibfk_1` FOREIGN KEY (`feed_id`) REFERENCES `feeds` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `feed_likes_user_id`
--
ALTER TABLE `feed_likes_user_id`
ADD CONSTRAINT `feed_likes_user_id_ibfk_1` FOREIGN KEY (`feed_id`) REFERENCES `feeds` (`id`) ON DELETE SET NULL ON UPDATE SET NULL,
ADD CONSTRAINT `feed_likes_user_id_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE SET NULL;
--
-- Constraints for table `profile_images`
--
ALTER TABLE `profile_images`
ADD CONSTRAINT `profile_images_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `remembered_logins`
--
ALTER TABLE `remembered_logins`
ADD CONSTRAINT `remembered_logins_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
--
-- Constraints for table `users`
--
ALTER TABLE `users`
ADD CONSTRAINT `users_ibfk_1` FOREIGN KEY (`department_id`) REFERENCES `departments` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;