-- --------------------------------------------------------
-- Host:                         127.0.0.1
-- Server version:               9.1.0 - MySQL Community Server - GPL
-- Server OS:                    Win64
-- HeidiSQL Version:             12.6.0.6765
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


-- Dumping database structure for musicquiz
CREATE DATABASE IF NOT EXISTS `musicquiz` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `musicquiz`;

-- Dumping structure for table musicquiz.artists
CREATE TABLE IF NOT EXISTS `artists` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Artists'' ID',
  `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'Artists'' name',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that saves data about song artists';

-- Dumping data for table musicquiz.artists: 0 rows
/*!40000 ALTER TABLE `artists` DISABLE KEYS */;
/*!40000 ALTER TABLE `artists` ENABLE KEYS */;

-- Dumping structure for table musicquiz.difficulty
CREATE TABLE IF NOT EXISTS `difficulty` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Difficulty ID',
  `name` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT 'Difficultie''s name',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that saves data about song difficulties';

-- Dumping data for table musicquiz.difficulty: 3 rows
/*!40000 ALTER TABLE `difficulty` DISABLE KEYS */;
INSERT INTO `difficulty` (`id`, `name`) VALUES
	(1, 'Easy'),
	(2, 'Medium'),
	(3, 'Hard');
/*!40000 ALTER TABLE `difficulty` ENABLE KEYS */;

-- Dumping structure for table musicquiz.game_runs
CREATE TABLE IF NOT EXISTS `game_runs` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Game ID',
  `user_id` int unsigned DEFAULT NULL COMMENT 'User ID (NULL if user is a guest)',
  `songs_count` tinyint unsigned NOT NULL COMMENT 'Song count (min 5, max 50)',
  `guess_time` tinyint unsigned NOT NULL COMMENT 'Guess time for each song (min 5 seconds, max 60 seconds)',
  `started_at` datetime NOT NULL DEFAULT (now()) COMMENT 'When did this game get started',
  `finished_at` datetime DEFAULT NULL COMMENT 'When did the game end',
  `points_earned` int NOT NULL DEFAULT '0' COMMENT 'How many points the user earned from this game (how many guesses are correct)',
  `xp_earned` int NOT NULL DEFAULT '0' COMMENT 'How much experience the user gained from this game',
  PRIMARY KEY (`id`),
  KEY `FK__users` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that saves data about games and their chosen settings';

-- Dumping data for table musicquiz.game_runs: 0 rows
/*!40000 ALTER TABLE `game_runs` DISABLE KEYS */;
/*!40000 ALTER TABLE `game_runs` ENABLE KEYS */;

-- Dumping structure for table musicquiz.run_rounds
CREATE TABLE IF NOT EXISTS `run_rounds` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Round ID',
  `game_runs_id` int unsigned NOT NULL COMMENT 'Game ID (FOREIGN KEY)',
  `round_index` tinyint unsigned NOT NULL COMMENT 'The round/question by order',
  `songs_id` int unsigned NOT NULL COMMENT 'The correct song''s ID (FOREIGN KEY)',
  `option1` int unsigned NOT NULL COMMENT 'First out of the 4 song options ',
  `option2` int unsigned NOT NULL COMMENT 'Second out of the 4 song options',
  `option3` int unsigned NOT NULL COMMENT 'Third out of the 4 song options',
  `option4` int unsigned NOT NULL COMMENT 'Fourth out of the 4 song options',
  `chosen_option` tinyint unsigned DEFAULT NULL COMMENT 'The user''s chosen option',
  `answered_at` datetime DEFAULT NULL COMMENT 'When did the user answer',
  `time_taken` int unsigned DEFAULT NULL COMMENT 'The time taken for the user to answer',
  `is_correct` int DEFAULT NULL COMMENT 'Did the user choose the correct option (songs_id = option?)',
  `xp_awarded` int NOT NULL DEFAULT '0' COMMENT 'The amount of xp earned in the round (depends on how quickly the user answered + was it correct)',
  PRIMARY KEY (`id`),
  KEY `FK_run_rounds_game_runs` (`game_runs_id`),
  KEY `FK_run_rounds_songs` (`songs_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that logs player''s game rounds';

-- Dumping data for table musicquiz.run_rounds: 0 rows
/*!40000 ALTER TABLE `run_rounds` DISABLE KEYS */;
/*!40000 ALTER TABLE `run_rounds` ENABLE KEYS */;

-- Dumping structure for table musicquiz.songs
CREATE TABLE IF NOT EXISTS `songs` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Song ID',
  `title` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT 'Song title',
  `release_date` date NOT NULL COMMENT 'Song''s release date',
  `video_url` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT 'Song''s music video URL',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that saves data about songs';

-- Dumping data for table musicquiz.songs: 0 rows
/*!40000 ALTER TABLE `songs` DISABLE KEYS */;
/*!40000 ALTER TABLE `songs` ENABLE KEYS */;

-- Dumping structure for table musicquiz.songs_artists
CREATE TABLE IF NOT EXISTS `songs_artists` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Song''s and artist''s relation ID',
  `songs_id` int unsigned NOT NULL COMMENT 'Song ID',
  `artists_id` int unsigned NOT NULL COMMENT 'Artist ID',
  PRIMARY KEY (`id`),
  KEY `FK__songs` (`songs_id`),
  KEY `FK__artists` (`artists_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that saves the relation of songs and artists';

-- Dumping data for table musicquiz.songs_artists: 0 rows
/*!40000 ALTER TABLE `songs_artists` DISABLE KEYS */;
/*!40000 ALTER TABLE `songs_artists` ENABLE KEYS */;

-- Dumping structure for table musicquiz.songs_difficulty
CREATE TABLE IF NOT EXISTS `songs_difficulty` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Song''s and difficultie''s relation ID',
  `songs_id` int unsigned NOT NULL COMMENT 'Song ID',
  `difficulty_id` int unsigned NOT NULL COMMENT 'Difficulty ID',
  PRIMARY KEY (`id`),
  KEY `FK__songs` (`songs_id`),
  KEY `FK__difficulty` (`difficulty_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that saves the relations between songs and their difficulty';

-- Dumping data for table musicquiz.songs_difficulty: 0 rows
/*!40000 ALTER TABLE `songs_difficulty` DISABLE KEYS */;
/*!40000 ALTER TABLE `songs_difficulty` ENABLE KEYS */;

-- Dumping structure for table musicquiz.users
CREATE TABLE IF NOT EXISTS `users` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'User ID',
  `username` varchar(50) COLLATE utf8mb4_general_ci NOT NULL COMMENT 'User''s username (UNIQUE KEY)',
  `bio` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'User''s bio, if added',
  `pfp` mediumblob COMMENT 'User''s pfp, if added',
  `password` varchar(255) COLLATE utf8mb4_general_ci NOT NULL COMMENT 'User''s encrypted password',
  `points` int NOT NULL DEFAULT '0' COMMENT 'User''s total points',
  `xp` int NOT NULL DEFAULT '0' COMMENT 'User''s total xp',
  `level` int NOT NULL DEFAULT '1' COMMENT 'User''s level',
  `created_at` datetime NOT NULL DEFAULT (now()) COMMENT 'User''s creation date and time',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table that saves data about users';

-- Dumping data for table musicquiz.users: 0 rows
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
/*!40000 ALTER TABLE `users` ENABLE KEYS */;

/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
