attach favorites to logged in user

This commit is contained in:
cwilvx
2024-05-25 15:12:44 +03:00
parent 300c8eb30b
commit 0b8a5e92f5
14 changed files with 128 additions and 38 deletions
+2 -1
View File
@@ -58,7 +58,8 @@ def apply_migrations():
try:
migration.migrate()
log.info("Applied migration: %s", migration.__name__)
except:
except Exception as e:
log.error("Failed to run migration: %s", migration.__name__)
log.error(e)
MigrationManager.set_index(len(all_migrations))
+22
View File
@@ -73,3 +73,25 @@ class _3MoveScrobbleToUserId1(Migration):
with SQLiteManager(userdata_db=True) as cur:
cur.execute("UPDATE track_logger SET userid = 1 WHERE userid = 0")
cur.close()
class _4AddUserIdToFavoritesTable(Migration):
"""
Adds a userid column to the favorites table.
"""
@staticmethod
def migrate():
# check if userid column exists
exists_sql = "select count(*) from pragma_table_info('favorites') where name = 'userid'"
sql = "ALTER TABLE favorites ADD userid INTEGER NOT NULL DEFAULT 1 REFERENCES users(id) ON DELETE CASCADE"
with SQLiteManager(userdata_db=True) as cur:
data = cur.execute(exists_sql)
data = data.fetchone()
if data[0] == 1:
return# INFO: column already exists
cur.executescript(sql)