· 8 years ago · May 09, 2018, 05:30 AM
1DROP TABLE IF EXISTS `users`;
2CREATE TABLE `users` (
3 `id` int(11) NOT NULL AUTO_INCREMENT,
4 `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
5 `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
6 `identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
7 `provider_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
8 `roles_mask` int(11) DEFAULT NULL,
9 `created_at` datetime DEFAULT NULL,
10 `updated_at` datetime DEFAULT NULL,
11 PRIMARY KEY (`id`),
12 UNIQUE KEY `index_users_on_identifier` (`identifier`)
13) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
14
15DROP TABLE IF EXISTS `etests`;
16CREATE TABLE `etests` (
17 `id` int(11) NOT NULL AUTO_INCREMENT,
18 `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
19 `content` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
20 `created_at` datetime DEFAULT NULL,
21 `updated_at` datetime DEFAULT NULL,
22 PRIMARY KEY (`id`)
23) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
24
25DROP TABLE IF EXISTS `questions`;
26CREATE TABLE `questions` (
27 `id` int(11) NOT NULL AUTO_INCREMENT,
28 `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
29 `content` text COLLATE utf8_unicode_ci,
30 `etest_id` int(11) DEFAULT NULL,
31 `created_at` datetime DEFAULT NULL,
32 `updated_at` datetime DEFAULT NULL,
33 PRIMARY KEY (`id`),
34 KEY `questions_etest_id_fk` (`etest_id`),
35 CONSTRAINT `questions_etest_id_fk` FOREIGN KEY (`etest_id`) REFERENCES `etests` (`id`)
36) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
37
38DROP TABLE IF EXISTS `answers`;
39CREATE TABLE `answers` (
40 `id` int(11) NOT NULL AUTO_INCREMENT,
41 `content` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
42 `correct` tinyint(1) DEFAULT NULL,
43 `question_id` int(11) DEFAULT NULL,
44 `created_at` datetime DEFAULT NULL,
45 `updated_at` datetime DEFAULT NULL,
46 PRIMARY KEY (`id`),
47 KEY `answers_question_id_fk` (`question_id`),
48 CONSTRAINT `answers_question_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions` (`id`)
49) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
50
51DROP TABLE IF EXISTS `user_tests`;
52CREATE TABLE `user_tests` (
53 `id` int(11) NOT NULL AUTO_INCREMENT,
54 `user_id` int(11) DEFAULT NULL,
55 `etest_id` int(11) DEFAULT NULL,
56 `done` tinyint(1) DEFAULT NULL,
57 `created_at` datetime DEFAULT NULL,
58 `updated_at` datetime DEFAULT NULL,
59 PRIMARY KEY (`id`),
60 KEY `user_tests_user_id_fk` (`user_id`),
61 KEY `user_tests_etest_id_fk` (`etest_id`),
62 CONSTRAINT `user_tests_etest_id_fk` FOREIGN KEY (`etest_id`) REFERENCES `etests` (`id`),
63 CONSTRAINT `user_tests_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
64) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
65
66DROP TABLE IF EXISTS `user_answers`;
67CREATE TABLE `user_answers` (
68 `id` int(11) NOT NULL AUTO_INCREMENT,
69 `answer_id` int(11) DEFAULT NULL,
70 `correct` tinyint(1) DEFAULT NULL,
71 `user_test_id` int(11) DEFAULT NULL,
72 `question_id` int(11) DEFAULT NULL,
73 `created_at` datetime DEFAULT NULL,
74 `updated_at` datetime DEFAULT NULL,
75 PRIMARY KEY (`id`),
76 KEY `user_answers_user_test_id_fk` (`user_test_id`),
77 KEY `user_answers_question_id_fk` (`question_id`),
78 KEY `user_answers_answer_id_fk` (`answer_id`),
79 CONSTRAINT `user_answers_answer_id_fk` FOREIGN KEY (`answer_id`) REFERENCES `answers` (`id`),
80 CONSTRAINT `user_answers_question_id_fk` FOREIGN KEY (`question_id`) REFERENCES `questions` (`id`),
81 CONSTRAINT `user_answers_user_test_id_fk` FOREIGN KEY (`user_test_id`) REFERENCES `user_tests` (`id`)
82) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;