diff --git a/build_db.py b/build_db.py index 82bdcea..086113d 100644 --- a/build_db.py +++ b/build_db.py @@ -27,7 +27,7 @@ cur.executemany( # import artist cur.executemany( 'insert into artist(id,name_rm,name) values(?, ?, ?)', - ((row[0],row[1],row[2]) for row in data['Artist'][1:]) + data['Artist'][1:] ) # import credit @@ -48,6 +48,12 @@ cur.executemany( data['Clip'][1:] ) +# import song x album +cur.executemany( + "insert into song_album(song_id,album_id,track) values (?, ?, ?)", + (row[:3] for row in data['Song'][1:]) +) + # import song x artist def creditparams(rows): for row in rows[1:]: @@ -56,13 +62,8 @@ def creditparams(rows): yield (row[0],artist,rows[0][index]) cur.executemany( - 'insert or ignore into song_artist(song_id,artist_id,credit_id) values (?, (select id from artist where coalesce(name_rm,name) = ?), (select id from credit where name = ?))', + 'insert or ignore into song_artist(song_id,artist_id,credit_id) values (?, (select id from artist where coalesce(nullif(name_rm,''),name) = ?), (select id from credit where name = ?))', creditparams(data['Song']) ) -cur.executemany( - "insert into song_album(song_id,album_id,track) values (?, ?, ?)", - ((row[0],row[1],row[2]) for row in data['Song'][1:]) -) - db.commit() \ No newline at end of file diff --git a/db.sql b/db.sql index b4de453..3d993dc 100644 --- a/db.sql +++ b/db.sql @@ -12,14 +12,6 @@ create table album( code char(3) not null ); -create table song_album( - song_id int not null references song(id), - album_id int not null references album(id), - track int not null, - primary key(album_id,track), - unique(song_id,album_id) -); - create table artist( id int primary key, name text not null, @@ -27,7 +19,7 @@ create table artist( ); create unique index ix_artist_name on artist( - coalesce(name_rm,name) + coalesce(nullif(name_rm,''),name) ); create table credit( @@ -35,17 +27,6 @@ create table credit( name text not null ); -create table song_artist( - song_id int not null references song(id), - artist_id int not null references artist(id), - credit_id int not null references credit(id), - primary key(song_id,artist_id,credit_id) -); - -create index ix_song_artist on song_artist( - artist_id -); - create table motif( id int primary key, name text not null @@ -63,3 +44,21 @@ create index ix_motif on clip( motif_id ); +create table song_album( + song_id int not null references song(id), + album_id int not null references album(id), + track int not null, + primary key(album_id,track), + unique(song_id,album_id) +); + +create table song_artist( + song_id int not null references song(id), + artist_id int not null references artist(id), + credit_id int not null references credit(id), + primary key(song_id,artist_id,credit_id) +); + +create index ix_song_artist on song_artist( + artist_id +); \ No newline at end of file diff --git a/generate.py b/generate.py index 532dfe6..dc7469f 100644 --- a/generate.py +++ b/generate.py @@ -15,10 +15,12 @@ songplate = environment.get_template("songpage.jinja") db = sqlite3.connect("songbook.sqlite") + for song in db.execute("SELECT name FROM song"): filename = f"public/song/{song[0]}" content = songplate.render( songname=song[0], + clips=() ) with open(filename, mode="w") as file: file.write(content) diff --git a/reference.ods b/reference.ods index ec82d51..0df0eb2 100644 Binary files a/reference.ods and b/reference.ods differ