Ensure Index exists after Song import

This commit is contained in:
Phillip Kühne 2023-10-04 00:33:15 +00:00
parent c50f00c1d3
commit c8b65e4433
Signed by: phillip
GPG Key ID: E4C1C4D2F90902AA

View File

@ -28,6 +28,11 @@ def import_songs(song_csv):
with get_db_engine().connect() as conn:
df.to_sql(song_table, conn, if_exists='replace',
index=False)
try:
cur = conn.execute(text("ALTER TABLE songs ADD FULLTEXT(Title,Artist)"))
conn.commit()
except Exception:
pass
cur = conn.execute(text("SELECT Count(Id) FROM songs"))
num_songs = cur.fetchone()[0] # type: ignore
conn.commit()