From 7df09f8b146ae7fb091787770fe5681381164f0e Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Wed, 2 Oct 2024 23:21:43 +0200 Subject: fix database setup --- scripts/populate/database.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'scripts/populate/database.py') diff --git a/scripts/populate/database.py b/scripts/populate/database.py index 2319812..eaccfd2 100644 --- a/scripts/populate/database.py +++ b/scripts/populate/database.py @@ -16,19 +16,17 @@ connector = mysql.connector.connect( cursor = connector.cursor() - - def process_albums(album_list): [process_album(album, album_id) for album_id, album in enumerate(album_list, 1)] def process_album(album, album_id): - upload_album(album) + upload_album(album, album_id) [upload_song(song, album_id) for song in album.songs] -def upload_album(album): +def upload_album(album, album_id): album.name = album.name.lower() cursor.execute(""" INSERT INTO album ( @@ -40,9 +38,19 @@ def upload_album(album): """, { 'name': album.name, 'cover': album.cover, - 'artist_id': album.artist + 'artist_id': album.artist, }) + if album.release: + cursor.execute(""" + UPDATE album + SET release_date = (%(release)s) + WHERE id = %(album_id)s; + """, { + 'release': album.release, + 'album_id': album_id, + }) + def upload_song(song, album_id): cursor.execute(""" -- cgit v1.2.3