-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `quiz_db`
--

-- --------------------------------------------------------

--
-- Table structure for table `answers`
--

CREATE TABLE `ja_nswers` (
  `id` int(11) NOT NULL,
  `question_id` int(11) DEFAULT NULL,
  `answer` text NOT NULL,
  `is_correct` tinyint(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `answers`
--

INSERT INTO `ja_answers` (`id`, `question_id`, `answer`, `is_correct`) VALUES
(221, 57, '2', 0),
(222, 57, '4', 1),
(223, 57, '8', 0),
(228, 60, '1', 0),
(229, 60, '2', 1),
(230, 60, '3', 0),
(231, 60, '4', 0),
(232, 61, '5', 0),
(233, 61, '6', 1),
(234, 61, '7', 0),
(235, 61, '8', 0),
(236, 62, 'a', 1),
(237, 62, 'a', 0),
(238, 62, 'a', 0),
(239, 62, 'a', 0),
(240, 63, 'a', 1),
(241, 63, 'a', 0),
(242, 63, 'a', 0),
(243, 63, 'a', 0),
(244, 64, '2', 0),
(245, 64, '8', 0),
(246, 64, '4', 1);

-- --------------------------------------------------------

--
-- Table structure for table `questions`
--

CREATE TABLE `ja_questions` (
  `id` int(11) NOT NULL,
  `test_id` int(11) DEFAULT NULL,
  `question` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `questions`
--

INSERT INTO `ja_questions` (`id`, `test_id`, `question`) VALUES
(57, 76, '2+2?'),
(60, 79, 'jautajums1'),
(61, 79, 'jautajums2'),
(62, 79, 'a'),
(63, 79, 'a'),
(64, 80, '2+2?');

-- --------------------------------------------------------

--
-- Table structure for table `tests`
--

CREATE TABLE `ja_tests` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `creator_id` int(11) DEFAULT NULL,
  `description` text NOT NULL,
  `category` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `tests`
--

INSERT INTO `ja_tests` (`id`, `name`, `creator_id`, `description`, `category`) VALUES
(76, 'test1123', 44, 'tests 1 tests', 'test123'),
(79, 'test3', 43, 'test3', 'test3'),
(80, 'Pirmais tests', 55, 'Šis ir pirmais tests.', 'Matemātika');

-- --------------------------------------------------------

--
-- Table structure for table `test_results`
--

CREATE TABLE `ja_test_results` (
  `id` int(11) NOT NULL,
  `test_id` int(11) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `score` int(11) NOT NULL,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `username` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dumping data for table `test_results`
--

INSERT INTO `ja_test_results` (`id`, `test_id`, `user_id`, `score`, `created_at`, `username`) VALUES
(86, 76, 43, 1, '2024-06-01 17:34:05', NULL),
(87, 76, 43, 1, '2024-06-01 17:39:59', NULL),
(88, 76, 43, 1, '2024-06-01 17:40:11', NULL),
(89, 76, 43, 1, '2024-06-01 17:41:52', NULL),
(90, 76, 43, 0, '2024-06-01 17:41:57', NULL),
(91, 79, 43, 1, '2024-06-01 18:15:13', NULL),
(92, 76, 43, 1, '2024-06-02 11:12:21', NULL),
(93, 80, 55, 1, '2024-06-02 13:57:31', NULL),
(94, 80, 44, 1, '2024-06-02 17:22:56', NULL),
(95, 79, 44, 2, '2024-06-02 17:23:04', NULL);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `answers`
--
ALTER TABLE `ja_answers`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_question_id` (`question_id`);

--
-- Indexes for table `questions`
--
ALTER TABLE `jaquestions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_test_id` (`test_id`);

--
-- Indexes for table `tests`
--
ALTER TABLE `jatests`
  ADD PRIMARY KEY (`id`),
  ADD KEY `creator_id` (`creator_id`);

--
-- Indexes for table `test_results`
--
ALTER TABLE `ja_test_results`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `fk_test_results_test_id` (`test_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `answers`
--
ALTER TABLE `ja_answers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=247;

--
-- AUTO_INCREMENT for table `questions`
--
ALTER TABLE `ja_questions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=65;

--
-- AUTO_INCREMENT for table `tests`
--
ALTER TABLE `ja_tests`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=85;

--
-- AUTO_INCREMENT for table `test_results`
--
ALTER TABLE `ja_test_results`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=96;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `answers`
--
ALTER TABLE `ja_answers`
  ADD CONSTRAINT `fk_question_id` FOREIGN KEY (`question_id`) REFERENCES `ja_questions` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `questions`
--
ALTER TABLE `ja_questions`
  ADD CONSTRAINT `fk_test_id` FOREIGN KEY (`test_id`) REFERENCES `ja_tests` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `tests`
--
ALTER TABLE `ja_tests`
  ADD CONSTRAINT `jtests_ibfk_1` FOREIGN KEY (`creator_id`) REFERENCES `ja_users` (`id`);

--
-- Constraints for table `test_results`
--
ALTER TABLE `ja_test_results`
  ADD CONSTRAINT `fk_test_results_test_id` FOREIGN KEY (`test_id`) REFERENCES `ja_tests` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `test_results_ibfk_1` FOREIGN KEY (`test_id`) REFERENCES `ja_tests` (`id`),
  ADD CONSTRAINT `test_results_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `ja_users` (`id`);
COMMIT;

