Commit eacd23d2 authored by Brian Guadalupe's avatar Brian Guadalupe

Merge branch 'test' into 'master'

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

See merge request brian/mymusiclist!5
parents 4225f9ff bd994527
=========DO NOT RUN===========
mymusiclist.sql
convert
extract.sql
Assuming you have sqlite3 installed and Django setup with migrations,
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
--artist extraction
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"
);
--album extraction
INSERT INTO album(id, album_name, year, artist_id)
select 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;
--song extraction
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,
playlist_name varchar(32) not null,
is_public boolean not null,
owner_id int,
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
-- currently unused
create table featured_songs(
song_id int unique,
FOREIGN KEY (song_id) REFERENCES song(song_id)
);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
from django.db import models from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
# Create your models here. class user_account(models.Model):
id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64)
email = models.CharField(max_length=64)
# class Profile(models.Model): class artist(models.Model):
# user = models.OneToOneField(User, on_delete=models.CASCADE) id = models.AutoField(primary_key=True)
# first_name = models.TextField(max_length=255) name = models.CharField(max_length=64)
# last_name = models.TextField(max_length=255) description = models.TextField()
# email_address = models.EmailField(max_length=255)
@receiver(post_save, sender=User) class album(models.Model):
def update_user_profile(sender, instance, created, **kwargs): id = models.AutoField(primary_key=True)
if created: album_name = models.CharField(max_length=64)
Profile.objects.create(user=instance) year = models.DecimalField(max_digits=4, decimal_places=0)
instance.profile.save() artist = models.ForeignKey(artist)
class song(models.Model):
id = models.AutoField(primary_key=True)
song_name = models.TextField()
genre = models.CharField(max_length=128)
song_length = models.PositiveIntegerField(default=0, null=True)
lyrics = models.TextField(null=True)
artist = models.ForeignKey(artist)
album = models.ForeignKey(album)
class music_playlist(models.Model):
id = models.AutoField(primary_key=True)
playlist_name = models.CharField(max_length=32)
is_public = models.BooleanField(default=False)
user = models.ForeignKey(user_account)
class music_entry(models.Model):
RATING_CHOICES = (
(0,'1'),
(1,'2'),
(2,'3'),
(3,'4'),
(4,'5'),
(5,'6'),
(6,'7'),
(7,'8'),
(8,'9'),
(9,'10')
)
id = models.AutoField(primary_key=True)
order_in_playlist = models.PositiveSmallIntegerField()
rating = models.DecimalField(max_digits=1, decimal_places=0, choices=RATING_CHOICES)
playlist = models.ForeignKey(music_playlist)
song = models.ForeignKey(song)
class tag(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=32)
tag = models.ManyToManyField(music_entry)
...@@ -122,7 +122,7 @@ body { ...@@ -122,7 +122,7 @@ body {
@font-face { @font-face {
font-family: 'PalanquinDark'; font-family: 'PalanquinDark';
src: url('../fonts/PalanquinDark-Regular.ttf'); src: url('/files/fonts/palanquindark/PalanquinDark-Regular.ttf');
} }
...@@ -32,12 +32,13 @@ ALLOWED_HOSTS = [] ...@@ -32,12 +32,13 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'core',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles'
] ]
MIDDLEWARE = [ MIDDLEWARE = [
...@@ -104,6 +105,7 @@ STATICFILES_FINDERS = [ ...@@ -104,6 +105,7 @@ STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder", "django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder", "django.contrib.staticfiles.finders.AppDirectoriesFinder",
] ]
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, "files"), os.path.join(BASE_DIR, "files"),
] ]
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>{% block title %}MyMusicList{% endblock %}</title> <title>{% block title %}MyMusicList{% endblock %}</title>
<link rel="stylesheet" href="/files/css/mymusiclist.css"> <link rel="stylesheet" href="/files/css/mymusiclist.css">
<link rel="stylesheet" href="/files/css/font-awesome.css">
</head> </head>
<body> <body>
<header> <header>
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
<li><a class="nav_bar_home" href="/">MyMusicList</a></li> <li><a class="nav_bar_home" href="/">MyMusicList</a></li>
<li><a class="nav_bar_tab" href="{% url 'login' %}">LOGIN</a></li> <li><a class="nav_bar_tab" href="{% url 'login' %}">LOGIN</a></li>
<li><a class="nav_bar_tab" href="{% url 'signup' %}">SIGN UP</a></li> <li><a class="nav_bar_tab" href="{% url 'signup' %}">SIGN UP</a></li>
<li style="float:right"><button class="nav_bar_tab"type="button" onclick="toggleWallpaper()"></button></li>
</ul> </ul>
{% endif %} {% endif %}
</header> </header>
...@@ -34,5 +36,10 @@ ...@@ -34,5 +36,10 @@
{% block content %} {% block content %}
{% endblock %} {% endblock %}
</main> </main>
<script>
function toggleWallpaper() {
document.getElementByID("nav_bar").style.background-color = "white";
}
</script>
</body> </body>
</html> </html>
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