From a7ae6a19771fbd5d0fda3caab67bbbfb4fd0ac4b Mon Sep 17 00:00:00 2001 From: echel0n Date: Tue, 22 Apr 2014 13:15:47 -0700 Subject: [PATCH] Fix for missing indexes --- sickbeard/databases/mainDB.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/sickbeard/databases/mainDB.py b/sickbeard/databases/mainDB.py index 36da6d78..326d2d77 100644 --- a/sickbeard/databases/mainDB.py +++ b/sickbeard/databases/mainDB.py @@ -100,21 +100,17 @@ class MainSanityCheck(db.DBSanityCheck): logger.log(u"No orphan episodes, check passed") def fix_missing_table_indexes(self): + if not self.connection.select("PRAGMA index_info('idx_indexer_id')"): + logger.log(u"Missing idx_indexer_id for TV Shows table detected!, fixing...") + self.connection.action("CREATE UNIQUE INDEX idx_indexer_id ON tv_shows (indexer_id);") - try: - sqlResults = self.connection.action("CREATE UNIQUE INDEX idx_indexer_id ON tv_shows (indexer_id);") - logger.log(u"Missing idx_indexer_id for TV Shows table added!") - except:pass + if not self.connection.select("PRAGMA index_info('idx_tv_episodes_showid_airdate')"): + logger.log(u"Missing idx_tv_episodes_showid_airdate for TV Episodes table detected!, fixing...") + self.connection.action("CREATE INDEX idx_tv_episodes_showid_airdate ON tv_episodes(showid,airdate);") - try: - sqlResults = self.connection.action("CREATE INDEX idx_tv_episodes_showid_airdate ON tv_episodes(showid,airdate);") - logger.log(u"Missing idx_tv_episodes_showid_airdate for TV Episodes table added!") - except:pass - - try: - sqlResults = self.connection.action("CREATE INDEX idx_showid ON tv_episodes (showid);") - logger.log(u"Missing idx_showid for TV Episodes table added!") - except:pass + if not self.connection.select("PRAGMA index_info('idx_showid')"): + logger.log(u"Missing idx_showid for TV Episodes table detected!, fixing...") + self.connection.action("CREATE INDEX idx_showid ON tv_episodes (showid);") def backupDatabase(version): logger.log(u"Backing up database before upgrade") @@ -534,7 +530,7 @@ class AddDvdOrderOption(AddLastProperSearch): def execute(self): backupDatabase(20) - self.connection.action("ALTER TABLE tv_shows ADD dvdorder NUMERIC") + self.connection.action("ALTER TABLE tv_shows ADD COLUMN dvdorder NUMERIC") self.incDBVersion()