-- MySQL dump 10.13  Distrib 5.6.26, for Linux (x86_64)
--
-- Host: localhost    Database: hathor_music
-- ------------------------------------------------------
-- 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_music`
--

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

USE `hathor_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',
  `name` varchar(255) NOT NULL COMMENT 'name of the album',
  `arid` varchar(64) NOT NULL COMMENT 'matching arist id from artist table',
  `albumartist` varchar(255) DEFAULT NULL COMMENT 'the album artist',
  `label` varchar(255) DEFAULT NULL COMMENT 'the album label',
  `released` year(4) DEFAULT '1969' COMMENT 'year released',
  `first_available` date DEFAULT '1969-01-01',
  `web` blob COMMENT 'json list of web sites for this album',
  `extra` blob COMMENT 'any extra information about this album in json format.',
  PRIMARY KEY (`id`),
  UNIQUE KEY `aid_albums_unq` (`aid`),
  KEY `aid_albums_idx` (`aid`),
  KEY `arid_albums_idx` (`arid`),
  CONSTRAINT `arid_albums` 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_artists` (`arid`),
  UNIQUE KEY `name_artists` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `covers`
--

DROP TABLE IF EXISTS `covers`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `covers` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'the unique id',
  `cid` varchar(64) DEFAULT NULL COMMENT 'cover id in md5',
  `aid` varchar(64) DEFAULT NULL COMMENT 'the album this belongs to',
  `file` varchar(1000) DEFAULT NULL COMMENT 'the actual filename',
  `base64` blob COMMENT 'base64 encoded output',
  `updated` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'last updated',
  PRIMARY KEY (`id`),
  KEY `cid_idx` (`cid`),
  KEY `aid_covers_idx` (`aid`),
  CONSTRAINT `covers_aid` FOREIGN KEY (`aid`) REFERENCES `albums` (`aid`) ON DELETE CASCADE ON UPDATE CASCADE
) 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`),
  KEY `playlist_uid_idx` (`uid`),
  KEY `playlist_track_idx` (`track`),
  CONSTRAINT `playlist_track_idx` FOREIGN KEY (`track`) REFERENCES `tracks` (`tid`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `playlist_uid_idx` 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',
  `uri` varchar(1000) NOT NULL DEFAULT 'unknown',
  `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',
  `lyrics` blob COMMENT 'lyrics if any',
  `comment` blob,
  `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 `tid_idx` (`tid`),
  UNIQUE KEY `id_idx` (`id`),
  KEY `tracks_arid` (`arid`),
  KEY `tracks_aid` (`aid`),
  CONSTRAINT `tracks_arid` FOREIGN KEY (`arid`) REFERENCES `artists` (`arid`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `tracks_aid` FOREIGN KEY (`aid`) REFERENCES `albums` (`aid`) 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 `username_idx` (`username`),
  UNIQUE KEY `email_idx` (`email`),
  UNIQUE KEY `id_idx` (`id`),
  UNIQUE KEY `uid_idx` (`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-30 12:07:30
