-- --------------------------------------------------------
-- Server OS:                    Win64
-- HeidiSQL Version:             12.6.0.6765
-- --------------------------------------------------------



-- 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

-- 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
INSERT INTO `difficulty` (`id`, `name`) VALUES
	(1, 'Easy'),
	(2, 'Medium'),
	(3, 'Hard');

-- 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

-- 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

-- 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

-- 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

-- 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



-- Dumping data for table musicquiz.users: 0 rows

