From ecb5395c2275b7b0aad0a4fc7ce8ba608939ef74 Mon Sep 17 00:00:00 2001 From: rembo10 Date: Sun, 19 Aug 2012 13:44:16 +0530 Subject: [PATCH] Better logic when upgrading from the old extras format to the new --- headphones/__init__.py | 11 +++++++---- headphones/mb.py | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/headphones/__init__.py b/headphones/__init__.py index 318607a0..129d37f7 100644 --- a/headphones/__init__.py +++ b/headphones/__init__.py @@ -887,12 +887,15 @@ def dbcheck(): try: c.execute('SELECT Extras from artists') except sqlite3.OperationalError: - # Need to update some stuff when people are upgrading and have the 'INCLUDE_EXTRAS' options selected + c.execute('ALTER TABLE artists ADD COLUMN Extras TEXT DEFAULT NULL') + # Need to update some stuff when people are upgrading and have 'include extras' set globally/for an artist if INCLUDE_EXTRAS: EXTRAS = "1,2,3,4,5,6,7,8" - c.execute('ALTER TABLE artists ADD COLUMN Extras TEXT DEFAULT "1,2,3,4,5,6,7,8"') - else: - c.execute('ALTER TABLE artists ADD COLUMN Extras TEXT DEFAULT NULL') + logger.info("Copying over current artist IncludeExtras information") + artists = c.execute('SELECT ArtistID, IncludeExtras from artists').fetchall() + for artist in artists: + if artist['IncludeExtras']: + c.execute('INSERT into artists Extras="1,2,3,4,5,6,7,8" WHERE ArtistID=' + artist['ArtistID']) conn.commit() c.close() diff --git a/headphones/mb.py b/headphones/mb.py index 83767d84..f81b7057 100644 --- a/headphones/mb.py +++ b/headphones/mb.py @@ -230,6 +230,7 @@ def getArtist(artistid, extrasonly=False): }) # See if we need to grab extras. Artist specific extras take precedence over global option + # Global options are set when adding a new artist myDB = db.DBConnection() try: