From e79b7fcd936fe4921cf55c26fbbbdf35f1752084 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Mon, 20 Jun 2016 02:46:10 +0100 Subject: [PATCH] Change improve importing show list sickbeard.db files. --- CHANGES.md | 7 +++++- sickbeard/databases/mainDB.py | 47 ++++++++++++++++++++++++++++++----- sickbeard/db.py | 12 ++++++--- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c84e8084..5f583fd9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,9 @@ -### 0.11.11 (2016-04-05 19:20:00 UTC) +### 0.11.12 (2016-06-20 02:20:00 UTC) + +* Change improve importing show list sickbeard.db files + + +### 0.11.11 (2016-04-05 19:20:00 UTC) * Add support for SD mkv container diff --git a/sickbeard/databases/mainDB.py b/sickbeard/databases/mainDB.py index f9d2dcce..1baf069d 100644 --- a/sickbeard/databases/mainDB.py +++ b/sickbeard/databases/mainDB.py @@ -977,15 +977,25 @@ class Migrate41(db.SchemaUpgrade): return self.checkDBVersion() -# 4301 -> 10001 +# 4301 -> 10002 class Migrate4301(db.SchemaUpgrade): def execute(self): db.backup_database('sickbeard.db', self.checkDBVersion()) - logger.log(u'Dropping redundant column') - self.dropColumn('db_version', 'db_minor_version') + logger.log(u'Bumping database version') - self.setDBVersion(10001) + self.setDBVersion(10002) + return self.checkDBVersion() + + +# 4302,4400 -> 10003 +class Migrate4302(db.SchemaUpgrade): + def execute(self): + db.backup_database('sickbeard.db', self.checkDBVersion()) + + logger.log(u'Bumping database version') + + self.setDBVersion(10003) return self.checkDBVersion() @@ -1016,13 +1026,38 @@ class RemoveDefaultEpStatusFromTvShows(db.SchemaUpgrade): def execute(self): db.backup_database('sickbeard.db', self.checkDBVersion()) - logger.log(u'Dropping column default_ep_status from tv_shows') + logger.log(u'Dropping redundant column default_ep_status from tv_shows') self.dropColumn('tv_shows', 'default_ep_status') self.setDBVersion(10000) return self.checkDBVersion() +# 10002 -> 10001 +class RemoveMinorDBVersion(db.SchemaUpgrade): + def execute(self): + db.backup_database('sickbeard.db', self.checkDBVersion()) + + logger.log(u'Dropping redundant column db_minor_version from db_version') + self.dropColumn('db_version', 'db_minor_version') + + self.setDBVersion(10001) + return self.checkDBVersion() + + +# 10003 -> 10002 +class RemoveMetadataSub(db.SchemaUpgrade): + def execute(self): + db.backup_database('sickbeard.db', self.checkDBVersion()) + + if self.hasColumn('tv_shows', 'sub_use_sr_metadata'): + logger.log(u'Dropping redundant column metadata sub') + self.dropColumn('tv_shows', 'sub_use_sr_metadata') + + self.setDBVersion(10002) + return self.checkDBVersion() + + # 20000 -> 20001 class DBIncreaseTo20001(db.SchemaUpgrade): def execute(self): @@ -1056,7 +1091,7 @@ class AddTvShowTags(db.SchemaUpgrade): db.backup_database('sickbeard.db', self.checkDBVersion()) if not self.hasColumn('tv_shows', 'tag'): - logger.log(u'Adding tag to tv_shows') + logger.log(u'Adding tag to tv_shows') self.addColumn('tv_shows', 'tag', 'TEXT', 'Show List') self.setDBVersion(20003) diff --git a/sickbeard/db.py b/sickbeard/db.py index f577c0fd..f4392b4f 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -75,11 +75,11 @@ class DBConnection(object): return 0 if result: - if self.hasColumn('db_version', 'db_minor_version'): + version = int(result[0]['db_version']) + if 10000 > version and self.hasColumn('db_version', 'db_minor_version'): minor = self.select('SELECT db_minor_version FROM db_version') - version = int(result[0]['db_version']) * 100 + int(minor[0]['db_minor_version']) - return (version, 4301)[2000301 == version] - return int(result[0]['db_version']) + return version * 100 + int(minor[0]['db_minor_version']) + return version else: return 0 @@ -427,6 +427,8 @@ def MigrationCode(myDB): 44: sickbeard.mainDB.Migrate41, 4301: sickbeard.mainDB.Migrate4301, + 4302: sickbeard.mainDB.Migrate4302, + 4400: sickbeard.mainDB.Migrate4302, 5816: sickbeard.mainDB.MigrateUpstream, 5817: sickbeard.mainDB.MigrateUpstream, @@ -434,6 +436,8 @@ def MigrationCode(myDB): 10000: sickbeard.mainDB.SickGearDatabaseVersion, 10001: sickbeard.mainDB.RemoveDefaultEpStatusFromTvShows, + 10002: sickbeard.mainDB.RemoveMinorDBVersion, + 10003: sickbeard.mainDB.RemoveMetadataSub, 20000: sickbeard.mainDB.DBIncreaseTo20001, 20001: sickbeard.mainDB.AddTvShowOverview,