diff options
author | nil0j <nil.jimeno@estudiant.fjaverianas.com> | 2024-09-26 17:22:30 +0200 |
---|---|---|
committer | nil0j <nil.jimeno@estudiant.fjaverianas.com> | 2024-09-26 17:22:30 +0200 |
commit | 9d70bfed33df8ea4cd77f915454da265edccf401 (patch) | |
tree | 571bae834dc5446e3c6e0f80b2efde55a3282081 /scrap/database.py | |
parent | 950bb3533cf59e074f485dfbb48fcf931e245ea6 (diff) |
separate sql initial script
Diffstat (limited to 'scrap/database.py')
-rw-r--r-- | scrap/database.py | 47 |
1 files changed, 1 insertions, 46 deletions
diff --git a/scrap/database.py b/scrap/database.py index dab2592..d7c0e0c 100644 --- a/scrap/database.py +++ b/scrap/database.py @@ -3,57 +3,12 @@ import mysql.connector connector = mysql.connector.connect( host="localhost", user="root", + database="balalaika", ) cursor = connector.cursor() -def setup(): - cursor.execute("CREATE DATABASE IF NOT EXISTS balalaika;") - cursor.execute("USE balalaika;") - cursor.execute("DROP TABLE IF EXISTS song;") - cursor.execute("DROP TABLE IF EXISTS album;") - cursor.execute("DROP TABLE IF EXISTS artist;") - - cursor.execute(""" - CREATE TABLE artist ( - id int NOT NULL AUTO_INCREMENT, - name varchar(255), - - PRIMARY KEY (id) - ); - """) - - cursor.execute(""" - CREATE TABLE album ( - id int NOT NULL AUTO_INCREMENT, - name varchar(255), - cover varchar(510), - artist_id int, - - PRIMARY KEY (id), - FOREIGN KEY (artist_id) REFERENCES artist(id) - ); - """) - - cursor.execute(""" - CREATE TABLE song ( - id int NOT NULL AUTO_INCREMENT, - name varchar(255), - lyrics TEXT, - - album_id int, - - PRIMARY KEY (id), - FOREIGN KEY (album_id) REFERENCES album(id) - ); - """) - - cursor.execute("ALTER TABLE song CONVERT TO CHARACTER SET utf8") - cursor.execute("ALTER TABLE album CONVERT TO CHARACTER SET utf8") - cursor.execute("ALTER TABLE artist CONVERT TO CHARACTER SET utf8") - - def process_albums(album_list): [process_album(album, album_id) for album_id, album in enumerate(album_list, 1)] |