Commit b2cc5ac2 authored by Gink's avatar Gink

Initial implementation of database with dummy data for both sqlite3 and sql.

parent 379d0bf9
=========DO NOT RUN===========
mymusiclist.sql
convert
extract.sql
Assuming you have sqlite3 installed,
While in same directory as db.sqlite3, run:
Sqlite3
.open db.sqlite3
.read SQL/sqlite3.sql
Now you can view tables with .tables and run sql statements
Assuming you have mysql installed, run:
Mysql
Use mymusiclist
Source sql/mysql.sql
#!/usr/bin/awk -f
# Authors: @esperlu, @artemyk, @gkuenning, @dumblob
BEGIN {
if (ARGC != 2) {
printf "%s\n%s\n",
"USAGE: mysql2sqlite dump_mysql.sql > dump_sqlite3.sql",
" file name - (dash) is not supported, because - means stdin" > "/dev/stderr"
err=1 # do not execute the END rule
exit 1
}
FS=",$"
print "PRAGMA synchronous = OFF;"
print "PRAGMA journal_mode = MEMORY;"
print "BEGIN TRANSACTION;"
}
# CREATE TRIGGER statements have funny commenting. Remember we are in trigger.
/^\/\*.*(CREATE.*TRIGGER|create.*trigger)/ {
gsub( /^.*(TRIGGER|trigger)/, "CREATE TRIGGER" )
print
inTrigger = 1
next
}
# The end of CREATE TRIGGER has a stray comment terminator
/(END|end) \*\/;;/ { gsub( /\*\//, "" ); print; inTrigger = 0; next }
# The rest of triggers just get passed through
inTrigger != 0 { print; next }
# CREATE VIEW looks like a TABLE in comments
/^\/\*.*(CREATE.*TABLE|create.*table)/ {
inView = 1
next
}
# The end of CREATE VIEW
/^(\).*(ENGINE|engine).*\*\/;)/ {
inView = 0;
next
}
# The rest of view just get passed through
inView != 0 { next }
# Skip other comments
/^\/\*/ { next }
# Print all `INSERT` lines. The single quotes are protected by another single quote.
( /^ *\(/ && /\) *[,;] *$/ ) || /^(INSERT|insert)/ {
prev = "";
gsub( /\\\047/, "\047\047" ) # single quote
gsub( /\\\047\047,/, "\\\047," )
gsub( /\\n/, "\n" )
gsub( /\\r/, "\r" )
gsub( /\\"/, "\"" )
gsub( /\\\\/, "\\" )
gsub( /\\\032/, "\032" ) # substitute
# sqlite3 is limited to 16 significant digits of precision
while ( match( $0, /0x[0-9a-fA-F]{17}/ ) ) {
hexIssue = 1
sub( /0x[0-9a-fA-F]+/, substr( $0, RSTART, RLENGTH-1 ), $0 )
}
print
next
}
# CREATE DATABASE is not supported
/^(CREATE.*DATABASE|create.*database)/ { next }
# Print the `CREATE` line as is and capture the table name.
/^(CREATE|create)/ {
if ( $0 ~ /IF NOT EXISTS|if not exists/ || $0 ~ /TEMPORARY|temporary/ ){
caseIssue = 1
}
if ( match( $0, /`[^`]+/ ) ) {
tableName = substr( $0, RSTART+1, RLENGTH-1 )
}
aInc = 0
prev = ""
firstInTable = 1
print
next
}
# Replace `FULLTEXT KEY` (probably other `XXXXX KEY`)
/^ (FULLTEXT KEY|fulltext key)/ { gsub( /.+(KEY|key)/, " KEY" ) }
# Get rid of field lengths in KEY lines
/ (PRIMARY |primary )?(KEY|key)/ { gsub( /\([0-9]+\)/, "" ) }
aInc == 1 && /PRIMARY KEY|primary key/ { next }
# Replace COLLATE xxx_xxxx_xx statements with COLLATE BINARY
/ (COLLATE|collate) [a-z0-9_]*/ { gsub( /(COLLATE|collate) [a-z0-9_]*/, "COLLATE BINARY" ) }
# Print all fields definition lines except the `KEY` lines.
/^ / && !/^( (KEY|key)|\);)/ {
if ( match( $0, /[^"`]AUTO_INCREMENT|auto_increment[^"`]/)) {
aInc = 1;
gsub( /AUTO_INCREMENT|auto_increment/, "PRIMARY KEY AUTOINCREMENT" )
}
gsub( /(UNIQUE KEY|unique key) `.*` /, "UNIQUE " )
gsub( /(CHARACTER SET|character set) [^ ]+[ ,]/, "" )
gsub( /DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP|default current_timestamp on update current_timestamp/, "" )
gsub( /(COLLATE|collate) [^ ]+ /, "" )
gsub( /(ENUM|enum)[^)]+\)/, "text " )
gsub( /(SET|set)\([^)]+\)/, "text " )
gsub( /UNSIGNED|unsigned/, "" )
gsub( /` [^ ]*(INT|int)[^ ]*/, "` integer" )
# field comments are not supported
gsub( / (COMMENT|comment).+$/, "" )
# Get commas off end of line
gsub( /,.?$/, "")
if ( prev ){
if ( firstInTable ){
print prev
firstInTable = 0
}
else print "," prev
}
else {
# FIXME check if this is correct in all cases
if ( match( $1,
/(CONSTRAINT|constraint) \".*\" (FOREIGN KEY|foreign key)/ ) )
print ","
}
prev = $1
}
/ ENGINE| engine/ {
if (prev) {
if (firstInTable) {
print prev
firstInTable = 0
}
else print "," prev
# else print prev
}
prev=""
print ");"
next
}
# `KEY` lines are extracted from the `CREATE` block and stored in array for later print
# in a separate `CREATE KEY` command. The index name is prefixed by the table name to
# avoid a sqlite error for duplicate index name.
/^( (KEY|key)|\);)/ {
if (prev) {
if (firstInTable) {
print prev
firstInTable = 0
}
else print "," prev
# else print prev
}
prev = ""
if ($0 == ");"){
print
} else {
if ( match( $0, /`[^`]+/ ) ) {
indexName = substr( $0, RSTART+1, RLENGTH-1 )
}
if ( match( $0, /\([^()]+/ ) ) {
indexKey = substr( $0, RSTART+1, RLENGTH-1 )
}
# idx_ prefix to avoid name clashes (they really happen!)
key[tableName]=key[tableName] "CREATE INDEX \"idx_" tableName "_" indexName "\" ON \"" tableName "\" (" indexKey ");\n"
}
}
END {
if (err) { exit 1};
# print all `KEY` creation lines.
for (table in key) printf key[table]
print "END TRANSACTION;"
if ( hexIssue ){
print "WARN Hexadecimal numbers longer than 16 characters has been trimmed." | "cat >&2"
}
if ( caseIssue ){
print "WARN Pure sqlite identifiers are case insensitive (even if quoted\n" \
" or if ASCII) and doesnt cross-check TABLE and TEMPORARY TABLE\n" \
" identifiers. Thus expect errors like \"table T has no column named F\"." | "cat >&2"
}
}
\ No newline at end of file
-- Do NOT RUN
INSERT INTO artist(id, name, description)
select ag.artistid, ag.name, "No description available" from artists_group ag where ag.name in
(
"Taylor Swift",
"Ed Sheeran",
"IU",
"The Script",
"Maroon 5",
"ZAYN",
"Khalid",
"Charlie Puth",
"Kygo",
"Akon",
"Imagine Dragons",
"P!ink",
"BTS",
"Calvin Harris",
"One Direction",
"Kendrick Lamar",
"Niall Horan",
"Avicii",
"LANY",
"Halsey",
"Jason Derulo",
"ClariS",
"Post Malone"
);
INSERT INTO album(id, album_name, year, artist_id)
select distinct tg.id, name, year, (select artistid from torrents_artists where groupid=tg.id order by importance asc limit 1) as artistidv
from torrents_group tg join torrents_artists ta on ta.groupid = tg.id
where (select artistid from torrents_artists where groupid=tg.id order by importance asc limit 1)
in (select id from artist) and (ta.artistid in (select id from artist)) and tg.releasetype=1 order by tg.id;
INSERT INTO song(song_name, genre, artist_id, album_id)
select (select filelist from torrents where groupid=album.id order by time desc limit 1), tg.taglist , artist.id, album.id
from artist join album on album.artist_id = artist.id join torrents_group tg on tg.id = album.id;
-- DO NOT RUN
create table user_account(
id int unique primary key auto_increment,
first_name varchar(64) not null,
last_name varchar(64) not null,
email varchar(64) not null
);
create table artist(
id int unique primary key auto_increment,
name varchar(64) not null,
description text
);
create table album(
id int unique primary key auto_increment,
album_name varchar(64) not null,
year int(4) not null,
artist_id int,
FOREIGN KEY (artist_id) REFERENCES artist(id)
);
create table song(
id int unique primary key auto_increment,
song_name mediumtext not null,
genre varchar(128),
song_length int DEFAULT 0,
lyrics text,
artist_id int not null,
album_id int,
FOREIGN KEY (artist_id) REFERENCES artist(id),
FOREIGN KEY (album_id) REFERENCES album(id)
);
create table music_playlist(
id int unique primary key auto_increment,
owner_id int,
playlist_name varchar(32) not null,
is_public boolean not null,
FOREIGN KEY (owner_id) REFERENCES user_account(id)
);
create table music_entry(
id int unique primary key auto_increment,
order_in_playlist int unique not null,
rating ENUM('1','2','3','4','5','6','7','8','9','10'),
playlist_id int not null,
song_id int not null,
FOREIGN KEY (playlist_id) REFERENCES music_playlist(id),
FOREIGN KEY (song_id) REFERENCES song(id)
);
create table tag(
id int unique primary key auto_increment,
name varchar(32) not null
)
create table tag_entry(
tag_id int,
entry_id int unique,
FOREIGN KEY (tag_id) REFERENCES tag(id),
FOREIGN KEY (entry_id) REFERENCES music_entry(id)
);
-- assuming we have featured songs
create table featured_songs(
song_id int unique,
FOREIGN KEY (song_id) REFERENCES song(song_id)
);
\ No newline at end of file
-- MySQL dump 10.13 Distrib 5.7.20, for Linux (x86_64)
--
-- Host: localhost Database: what_db
-- ------------------------------------------------------
-- Server version 5.7.20
/*!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 */;
--
-- Table structure for table `user_account`
--
DROP TABLE IF EXISTS `user_account`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user_account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(64) NOT NULL,
`last_name` varchar(64) NOT NULL,
`email` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `user_account`
--
LOCK TABLES `user_account` WRITE;
/*!40000 ALTER TABLE `user_account` DISABLE KEYS */;
/*!40000 ALTER TABLE `user_account` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `artist`
--
DROP TABLE IF EXISTS `artist`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `artist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
`description` text,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1427742 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `artist`
--
LOCK TABLES `artist` WRITE;
/*!40000 ALTER TABLE `artist` DISABLE KEYS */;
INSERT INTO `artist` VALUES (409,'Akon','No description available'),(2822,'Maroon 5','No description available'),(3457,'Calvin Harris','No description available'),(14571,'Taylor Swift','No description available'),(42820,'The Script','No description available'),(137257,'Avicii','No description available'),(204743,'Jason Derulo','No description available'),(209178,'Khalid','No description available'),(348773,'Imagine Dragons','No description available'),(383287,'Kendrick Lamar','No description available'),(463487,'ClariS','No description available'),(464253,'Ed Sheeran','No description available'),(475312,'Charlie Puth','No description available'),(613412,'One Direction','No description available'),(986658,'Kygo','No description available'),(1033658,'Zayn','No description available'),(1117531,'Halsey','No description available'),(1189739,'BTS','No description available'),(1243225,'LANY','No description available'),(1427741,'Niall Horan','No description available');
/*!40000 ALTER TABLE `artist` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `album`
--
DROP TABLE IF EXISTS `album`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `album` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`album_name` varchar(64) NOT NULL,
`year` int(4) NOT NULL,
`artist_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `artist_id` (`artist_id`),
CONSTRAINT `album_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=73233718 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `album`
--
LOCK TABLES `album` WRITE;
/*!40000 ALTER TABLE `album` DISABLE KEYS */;
INSERT INTO `album` VALUES (5855,'Trouble',2003,409),(13544,'Konvicted',2006,409),(19129,'Songs About Jane',2002,2822),(19602,'I Created Disco',2007,3457),(30519,'Taylor Swift',2006,14571),(37318,'It Won\'t Be Soon Before Long',2007,2822),(203718,'The Script',2008,42820),(295240,'Fearless',2008,14571),(311226,'Freedom',2008,409),(538314,'Ready for the Weekend',2009,3457),(710818,'Jason Derülo',2010,204743),(857392,'Hands All Over',2010,2822),(857450,'Science & Faith',2010,42820),(71829076,'Speak Now',2010,14571),(72002104,'Section.80',2011,383287),(72045386,'+',2011,464253),(72048111,'Future History',2011,204743),(72087084,'Up All Night',2011,613412),(72184080,'BIRTHDAY',2012,463487),(72237573,'Overexposed',2012,2822),(72285595,'Night Visions',2012,348773),(72286759,'#3',2012,42820),(72318070,'good kid, m.A.A.d city',2012,383287),(72318105,'Red',2012,14571),(72324214,'18 Months',2012,3457),(72335503,'Take Me Home',2012,613412),(72519340,'SECOND STORY',2013,463487),(72572571,'TRUE',2013,137257),(72577095,'Tattoos',2013,204743),(72619052,'Midnight Memories',2013,613412),(72701191,'Talk Dirty',2014,204743),(72731395,'PARTY TIME',2014,463487),(72740625,'×',2014,464253),(72783778,'V',2014,2822),(72792151,'No Sound Without Silence',2014,42820),(72817155,'1989',2014,14571),(72819437,'Motion',2014,3457),(72829519,'Four',2014,613412),(72902118,'Smoke + Mirrors',2015,348773),(72926857,'To Pimp a Butterfly',2015,383287),(72981909,'Everything Is 4',2015,204743),(73045308,'Badlands',2015,1117531),(73068131,'Stories',2015,137257),(73098814,'Made In the A.M.',2015,613412),(73155604,'Nine Track Mind',2016,475312),(73184511,'untitled unmastered.',2016,383287),(73198864,'Mind of Mine',2016,1033658),(73233717,'Cloud Nine',2016,986658);
/*!40000 ALTER TABLE `album` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `song`
--
DROP TABLE IF EXISTS `song`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `song` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`song_name` mediumtext NOT NULL,
`genre` varchar(128) DEFAULT NULL,
`song_length` int(11) DEFAULT '0',
`lyrics` text,
`artist_id` int(11) NOT NULL,
`album_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `artist_id` (`artist_id`),
KEY `album_id` (`album_id`),
CONSTRAINT `song_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`),
CONSTRAINT `song_ibfk_2` FOREIGN KEY (`album_id`) REFERENCES `album` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `song`
--
LOCK TABLES `song` WRITE;
/*!40000 ALTER TABLE `song` DISABLE KEYS */;
/*!40000 ALTER TABLE `song` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `music_playlist`
--
DROP TABLE IF EXISTS `music_playlist`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `music_playlist` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_id` int(11) DEFAULT NULL,
`playlist_name` varchar(32) NOT NULL,
`is_public` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `owner_id` (`owner_id`),
CONSTRAINT `music_playlist_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `user_account` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `music_playlist`
--
LOCK TABLES `music_playlist` WRITE;
/*!40000 ALTER TABLE `music_playlist` DISABLE KEYS */;
/*!40000 ALTER TABLE `music_playlist` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `music_entry`
--
DROP TABLE IF EXISTS `music_entry`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `music_entry` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_in_playlist` int(11) NOT NULL,
`rating` enum('1','2','3','4','5','6','7','8','9','10') DEFAULT NULL,
`playlist_id` int(11) NOT NULL,
`song_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
UNIQUE KEY `order_in_playlist` (`order_in_playlist`),
KEY `playlist_id` (`playlist_id`),
KEY `song_id` (`song_id`),
CONSTRAINT `music_entry_ibfk_1` FOREIGN KEY (`playlist_id`) REFERENCES `music_playlist` (`id`),
CONSTRAINT `music_entry_ibfk_2` FOREIGN KEY (`song_id`) REFERENCES `song` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `music_entry`
--
LOCK TABLES `music_entry` WRITE;
/*!40000 ALTER TABLE `music_entry` DISABLE KEYS */;
/*!40000 ALTER TABLE `music_entry` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tag`
--
DROP TABLE IF EXISTS `tag`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tag` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `tag`
--
LOCK TABLES `tag` WRITE;
/*!40000 ALTER TABLE `tag` DISABLE KEYS */;
/*!40000 ALTER TABLE `tag` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `tag_entry`
--
DROP TABLE IF EXISTS `tag_entry`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tag_entry` (
`tag_id` int(11) DEFAULT NULL,
`entry_id` int(11) DEFAULT NULL,
UNIQUE KEY `entry_id` (`entry_id`),
KEY `tag_id` (`tag_id`),
CONSTRAINT `tag_entry_ibfk_1` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`),
CONSTRAINT `tag_entry_ibfk_2` FOREIGN KEY (`entry_id`) REFERENCES `music_entry` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `tag_entry`
--
LOCK TABLES `tag_entry` WRITE;
/*!40000 ALTER TABLE `tag_entry` DISABLE KEYS */;
/*!40000 ALTER TABLE `tag_entry` ENABLE KEYS */;
UNLOCK TABLES;
/*!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 2017-10-31 9:52:13
PRAGMA synchronous = OFF;
PRAGMA journal_mode = MEMORY;
BEGIN TRANSACTION;
CREATE TABLE `user_account` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `first_name` varchar(64) NOT NULL
, `last_name` varchar(64) NOT NULL
, `email` varchar(64) NOT NULL
, UNIQUE (`id`)
);
CREATE TABLE `artist` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `name` varchar(64) NOT NULL
, `description` text
, UNIQUE (`id`)
);
INSERT INTO `artist` VALUES (409,'Akon','No description available'),(2822,'Maroon 5','No description available'),(3457,'Calvin Harris','No description available'),(14571,'Taylor Swift','No description available'),(42820,'The Script','No description available'),(137257,'Avicii','No description available'),(204743,'Jason Derulo','No description available'),(209178,'Khalid','No description available'),(348773,'Imagine Dragons','No description available'),(383287,'Kendrick Lamar','No description available'),(463487,'ClariS','No description available'),(464253,'Ed Sheeran','No description available'),(475312,'Charlie Puth','No description available'),(613412,'One Direction','No description available'),(986658,'Kygo','No description available'),(1033658,'Zayn','No description available'),(1117531,'Halsey','No description available'),(1189739,'BTS','No description available'),(1243225,'LANY','No description available'),(1427741,'Niall Horan','No description available');
CREATE TABLE `album` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `album_name` varchar(64) NOT NULL
, `year` integer NOT NULL
, `artist_id` integer DEFAULT NULL
, UNIQUE (`id`)
, CONSTRAINT `album_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`)
);
INSERT INTO `album` VALUES (5855,'Trouble',2003,409),(13544,'Konvicted',2006,409),(19129,'Songs About Jane',2002,2822),(19602,'I Created Disco',2007,3457),(30519,'Taylor Swift',2006,14571),(37318,'It Won''t Be Soon Before Long',2007,2822),(203718,'The Script',2008,42820),(295240,'Fearless',2008,14571),(311226,'Freedom',2008,409),(538314,'Ready for the Weekend',2009,3457),(710818,'Jason Derülo',2010,204743),(857392,'Hands All Over',2010,2822),(857450,'Science & Faith',2010,42820),(71829076,'Speak Now',2010,14571),(72002104,'Section.80',2011,383287),(72045386,'+',2011,464253),(72048111,'Future History',2011,204743),(72087084,'Up All Night',2011,613412),(72184080,'BIRTHDAY',2012,463487),(72237573,'Overexposed',2012,2822),(72285595,'Night Visions',2012,348773),(72286759,'#3',2012,42820),(72318070,'good kid, m.A.A.d city',2012,383287),(72318105,'Red',2012,14571),(72324214,'18 Months',2012,3457),(72335503,'Take Me Home',2012,613412),(72519340,'SECOND STORY',2013,463487),(72572571,'TRUE',2013,137257),(72577095,'Tattoos',2013,204743),(72619052,'Midnight Memories',2013,613412),(72701191,'Talk Dirty',2014,204743),(72731395,'PARTY TIME',2014,463487),(72740625,'×',2014,464253),(72783778,'V',2014,2822),(72792151,'No Sound Without Silence',2014,42820),(72817155,'1989',2014,14571),(72819437,'Motion',2014,3457),(72829519,'Four',2014,613412),(72902118,'Smoke + Mirrors',2015,348773),(72926857,'To Pimp a Butterfly',2015,383287),(72981909,'Everything Is 4',2015,204743),(73045308,'Badlands',2015,1117531),(73068131,'Stories',2015,137257),(73098814,'Made In the A.M.',2015,613412),(73155604,'Nine Track Mind',2016,475312),(73184511,'untitled unmastered.',2016,383287),(73198864,'Mind of Mine',2016,1033658),(73233717,'Cloud Nine',2016,986658);
CREATE TABLE `song` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `song_name` mediumtext NOT NULL
, `genre` varchar(128) DEFAULT NULL
, `song_length` integer DEFAULT '0'
, `lyrics` text
, `artist_id` integer NOT NULL
, `album_id` integer DEFAULT NULL
, UNIQUE (`id`)
, CONSTRAINT `song_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`)
, CONSTRAINT `song_ibfk_2` FOREIGN KEY (`album_id`) REFERENCES `album` (`id`)
);
CREATE TABLE `music_playlist` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `owner_id` integer DEFAULT NULL
, `playlist_name` varchar(32) NOT NULL
, `is_public` integer NOT NULL
, UNIQUE (`id`)
, CONSTRAINT `music_playlist_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `user_account` (`id`)
);
CREATE TABLE `music_entry` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `order_in_playlist` integer NOT NULL
, `rating` text DEFAULT NULL
, `playlist_id` integer NOT NULL
, `song_id` integer NOT NULL
, UNIQUE (`id`)
, UNIQUE (`order_in_playlist`)
, CONSTRAINT `music_entry_ibfk_1` FOREIGN KEY (`playlist_id`) REFERENCES `music_playlist` (`id`)
, CONSTRAINT `music_entry_ibfk_2` FOREIGN KEY (`song_id`) REFERENCES `song` (`id`)
);
CREATE TABLE `tag` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `name` varchar(32) NOT NULL
, UNIQUE (`id`)
);
CREATE TABLE `tag_entry` (
`tag_id` integer DEFAULT NULL
, `entry_id` integer DEFAULT NULL
, UNIQUE (`entry_id`)
, CONSTRAINT `tag_entry_ibfk_1` FOREIGN KEY (`tag_id`) REFERENCES `tag` (`id`)
, CONSTRAINT `tag_entry_ibfk_2` FOREIGN KEY (`entry_id`) REFERENCES `music_entry` (`id`)
);
CREATE INDEX "idx_album_artist_id" ON "album" (`artist_id`);
CREATE INDEX "idx_music_playlist_owner_id" ON "music_playlist" (`owner_id`);
CREATE INDEX "idx_tag_entry_tag_id" ON "tag_entry" (`tag_id`);
CREATE INDEX "idx_music_entry_playlist_id" ON "music_entry" (`playlist_id`);
CREATE INDEX "idx_music_entry_song_id" ON "music_entry" (`song_id`);
CREATE INDEX "idx_song_artist_id" ON "song" (`artist_id`);
CREATE INDEX "idx_song_album_id" ON "song" (`album_id`);
END TRANSACTION;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment