-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jun 25, 2025 at 03:14 AM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.2.14

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: `quiz_competition_db`
--

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

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

CREATE TABLE `answers` (
  `id` int(11) NOT NULL,
  `participant_id` int(11) NOT NULL,
  `session_id` int(11) NOT NULL,
  `question_id` int(11) NOT NULL,
  `user_answer` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `is_correct` tinyint(1) NOT NULL,
  `answered_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

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

INSERT INTO `answers` (`id`, `participant_id`, `session_id`, `question_id`, `user_answer`, `is_correct`, `answered_at`) VALUES
(14, 17, 17, 1, 'Jakarta', 1, '2025-06-24 23:35:43'),
(15, 17, 17, 2, '38', 1, '2025-06-24 23:36:16'),
(16, 17, 17, 3, 'Soekarno', 1, '2025-06-24 23:37:11'),
(17, 18, 18, 1, 'Jakarta', 1, '2025-06-24 23:47:27'),
(18, 18, 18, 2, '38', 1, '2025-06-24 23:50:16'),
(19, 18, 18, 3, 'BJ Habibie', 0, '2025-06-24 23:51:35'),
(20, 19, 19, 1, 'Jakarta', 1, '2025-06-24 23:57:49'),
(21, 21, 20, 1, 'Jakarta', 1, '2025-06-25 00:05:18'),
(22, 22, 20, 1, 'Jakarta', 1, '2025-06-25 00:06:06'),
(23, 22, 20, 2, '38', 1, '2025-06-25 00:06:18');

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

--
-- Table structure for table `participants`
--

CREATE TABLE `participants` (
  `id` int(11) NOT NULL,
  `session_id` int(11) NOT NULL,
  `participant_name` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `score` int(11) DEFAULT '0',
  `tab_violation_count` int(11) DEFAULT '0',
  `inactivity_violation_count` int(11) DEFAULT '0',
  `is_disqualified` tinyint(1) DEFAULT '0',
  `joined_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `last_activity_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

--
-- Dumping data for table `participants`
--

INSERT INTO `participants` (`id`, `session_id`, `participant_name`, `score`, `tab_violation_count`, `inactivity_violation_count`, `is_disqualified`, `joined_at`, `last_activity_at`) VALUES
(16, 16, 'Hendra', 0, 3, 0, 0, '2025-06-24 23:31:17', '2025-06-24 23:35:32'),
(17, 17, 'Hendra', 3, 3, 0, 1, '2025-06-24 23:35:36', '2025-06-24 23:37:29'),
(18, 18, 'Hendra', 2, 6, 0, 0, '2025-06-24 23:47:08', '2025-06-24 23:51:35'),
(19, 19, 'Tes 1', 1, 5, 0, 1, '2025-06-24 23:57:35', '2025-06-25 00:04:54'),
(20, 19, 'Hendra', 0, 0, 0, 0, '2025-06-25 00:01:10', '2025-06-25 00:01:10'),
(21, 20, 'Hendra', 1, 2, 0, 0, '2025-06-25 00:05:03', '2025-06-25 00:05:22'),
(22, 20, 'Tes 2', 2, 4, 0, 1, '2025-06-25 00:05:57', '2025-06-25 00:06:33');

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

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

CREATE TABLE `questions` (
  `id` int(11) NOT NULL,
  `question_text` text COLLATE latin1_general_ci NOT NULL,
  `option_a` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `option_b` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `option_c` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `option_d` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `correct_answer` varchar(255) COLLATE latin1_general_ci NOT NULL,
  `question_order` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

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

INSERT INTO `questions` (`id`, `question_text`, `option_a`, `option_b`, `option_c`, `option_d`, `correct_answer`, `question_order`) VALUES
(1, 'Apa nama ibu kota Indonesia?', 'Surabaya', 'Bandung', 'Jakarta', 'Medan', 'Jakarta', 1),
(2, 'Berapa jumlah provinsi di Indonesia saat ini (per 2024)?', '34', '36', '38', '39', '38', 2),
(3, 'Siapa presiden pertama Republik Indonesia?', 'Soeharto', 'BJ Habibie', 'Soekarno', 'Joko Widodo', 'Soekarno', 3),
(4, 'Alat musik tradisional apakah yang berasal dari Jawa Barat dan terbuat dari bambu?', 'Gamelan', 'Angklung', 'Kolintang', 'Sasando', 'Angklung', 4),
(5, 'Penyakit apakah yang disebabkan oleh virus HIV?', 'Demam Berdarah', 'TBC', 'AIDS', 'Malaria', 'AIDS', 5),
(6, 'Tarian daerah yang berasal dari Bali dan dikenal dengan gerakan dinamisnya adalah?', 'Tari Saman', 'Tari Kecak', 'Tari Jaipong', 'Tari Piring', 'Tari Kecak', 6),
(7, 'Danau terbesar di Indonesia yang juga merupakan danau vulkanik adalah?', 'Danau Toba', 'Danau Singkarak', 'Danau Maninjau', 'Danau Ranau', 'Danau Toba', 7);

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

--
-- Table structure for table `quiz_sessions`
--

CREATE TABLE `quiz_sessions` (
  `id` int(11) NOT NULL,
  `session_code` varchar(10) COLLATE latin1_general_ci NOT NULL,
  `current_question_order` int(11) DEFAULT '0',
  `status` enum('waiting','in_progress','finished') COLLATE latin1_general_ci DEFAULT 'waiting',
  `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;

--
-- Dumping data for table `quiz_sessions`
--

INSERT INTO `quiz_sessions` (`id`, `session_code`, `current_question_order`, `status`, `last_update`, `created_at`) VALUES
(16, 'SQ4RTG', 0, 'waiting', '2025-06-24 23:30:55', '2025-06-24 23:30:55'),
(17, '0CMWSU', 4, 'finished', '2025-06-24 23:46:22', '2025-06-24 23:34:30'),
(18, 'NUZARE', 3, 'finished', '2025-06-24 23:51:58', '2025-06-24 23:46:35'),
(19, '9E6CBM', 1, 'finished', '2025-06-25 00:04:40', '2025-06-24 23:57:15'),
(20, '3V8H6M', 2, 'finished', '2025-06-25 01:02:04', '2025-06-25 00:04:46');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `answers`
--
ALTER TABLE `answers`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `participant_id` (`participant_id`,`question_id`),
  ADD KEY `session_id` (`session_id`),
  ADD KEY `question_id` (`question_id`);

--
-- Indexes for table `participants`
--
ALTER TABLE `participants`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `session_id` (`session_id`,`participant_name`);

--
-- Indexes for table `questions`
--
ALTER TABLE `questions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `question_order` (`question_order`);

--
-- Indexes for table `quiz_sessions`
--
ALTER TABLE `quiz_sessions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `session_code` (`session_code`);

--
-- AUTO_INCREMENT for dumped tables
--

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

--
-- AUTO_INCREMENT for table `participants`
--
ALTER TABLE `participants`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23;

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

--
-- AUTO_INCREMENT for table `quiz_sessions`
--
ALTER TABLE `quiz_sessions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `answers`
--
ALTER TABLE `answers`
  ADD CONSTRAINT `answers_ibfk_1` FOREIGN KEY (`participant_id`) REFERENCES `participants` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `answers_ibfk_2` FOREIGN KEY (`session_id`) REFERENCES `quiz_sessions` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `answers_ibfk_3` FOREIGN KEY (`question_id`) REFERENCES `questions` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `participants`
--
ALTER TABLE `participants`
  ADD CONSTRAINT `participants_ibfk_1` FOREIGN KEY (`session_id`) REFERENCES `quiz_sessions` (`id`) ON DELETE 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 */;
