-- MySQL dump 10.13  Distrib 5.6.26, for Linux (x86_64)
--
-- Host: localhost    Database: hathor
-- ------------------------------------------------------
-- Server version	5.6.26-log

/*!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 utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!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 */;

--
-- Current Database: `hathor`
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `music` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `music`;

--
-- Table structure for table `albums`
--

DROP TABLE IF EXISTS `albums`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `albums` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the album',
  `aid` varchar(64) NOT NULL COMMENT 'album id in md5',
  `arid` varchar(64) NOT NULL COMMENT 'matching arist id from artist table',
  `released` year(4) DEFAULT '1969' COMMENT 'year released',
  `web` blob COMMENT 'json list of web sites for this album',
  `extra` blob COMMENT 'any extra information about this album in json format.',
  `first_available` date DEFAULT '1969-01-01',
  PRIMARY KEY (`id`),
  UNIQUE KEY `aid_hathor` (`aid`),
  UNIQUE KEY `arid_hathor` (`arid`),
  FOREIGN KEY (`arid`) REFERENCES `artists` (`arid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `artists`
--

DROP TABLE IF EXISTS `artists`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `artists` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `arid` varchar(64) NOT NULL COMMENT 'unique artist id in md5 format',
  `name` varchar(255) NOT NULL COMMENT 'name of the artist',
  `web` blob COMMENT 'json formated information with different web sites',
  `tour` blob COMMENT 'json formated information about touring',
  `rating` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT 'rating from 1 to 10 of artist',
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'updated timestamp',
  `extra` blob COMMENT 'any extra information about artist in json format',
  PRIMARY KEY (`id`),
  UNIQUE KEY `arid_hathor` (`arid`),
  UNIQUE KEY `name_hathor` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `playlists`
--

DROP TABLE IF EXISTS `playlists`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `playlists` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'playlist id',
  `uid` varchar(64) NOT NULL COMMENT 'uid in the users table in md5',
  `plsid` varchar(64) NOT NULL COMMENT 'playlist id in md5',
  `name` varchar(255) NOT NULL COMMENT 'name for this playlist',
  `track` varchar(64) NOT NULL COMMENT 'the track in md5 format from the tracks table',
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'playlist last updated timestamp',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uid_hathor` (`uid`),
  UNIQUE KEY `uid_pls_hathor` (`uid`),
  KEY `playlist_track_idx` (`track`),
  FOREIGN KEY (`track`) REFERENCES `tracks` (`tid`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`uid`) REFERENCES `users` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `tracks`
--

DROP TABLE IF EXISTS `tracks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tracks` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id of the song in the database',
  `tid` varchar(64) NOT NULL COMMENT 'song id md5 hash',
  `arid` varchar(64) NOT NULL COMMENT 'corresponding artist id from artist table in md5 hash',
  `aid` varchar(64) NOT NULL COMMENT 'corresponding album id from album table in md5 hash',
  `title` varchar(255) NOT NULL COMMENT 'title of song',
  `track` tinyint(4) unsigned DEFAULT '0' COMMENT 'track number of song',
  `genre` varchar(45) DEFAULT NULL COMMENT 'genre of song',
  `year` tinyint(4) DEFAULT '0' COMMENT 'year of song',
  `label` varchar(255) DEFAULT NULL COMMENT 'music label of song e.g. Columbia Records',
  `lyrics` blob COMMENT 'lyrics if any',
  `bitrate` mediumint(6) unsigned DEFAULT '0' COMMENT 'bitrate of song',
  `sample` mediumint(6) unsigned DEFAULT '0' COMMENT 'sample rate of song',
  `channels` smallint(2) unsigned DEFAULT '0' COMMENT 'channels of song i.e stereo = 2, mono = 1',
  `length` int(10) unsigned DEFAULT '0' COMMENT 'length of song',
  `minutes` tinytext COMMENT 'total length of song in minutes and seconds',
  `seconds` tinyint(4) unsigned DEFAULT '0' COMMENT 'seconds of song',
  `pls` blob COMMENT 'playlists this song is associated with',
  `ts` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'timestamp of last update of song',
  PRIMARY KEY (`id`),
  UNIQUE KEY `arid_hathor` (`arid`) USING BTREE,
  UNIQUE KEY `aid_hathor` (`aid`),
  UNIQUE KEY `title_hathor` (`title`),
  UNIQUE KEY `sid_hathor` (`tid`),
  FOREIGN KEY (`aid`) REFERENCES `albums` (`aid`) ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (`arid`) REFERENCES `artists` (`arid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `users`
--

DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'the user id int',
  `uid` varchar(64) NOT NULL COMMENT 'user id in md5',
  `username` varchar(20) NOT NULL COMMENT 'the users name',
  `email` varchar(255) NOT NULL COMMENT 'the users email',
  `password` varchar(255) NOT NULL COMMENT 'the users hashed password',
  `isadmin` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT 'true or false, admin rights',
  `pls` blob COMMENT 'json list of playlist ids',
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'timestamp of user record',
  PRIMARY KEY (`id`),
  UNIQUE KEY `hathor_username` (`username`),
  UNIQUE KEY `hathor_email` (`email`),
  UNIQUE KEY `hathor_id` (`id`),
  UNIQUE KEY `hathor_uid` (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!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 */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2015-08-15 21:43:51
