mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
attach favorites to logged in user
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user