2014-03-10 05:18:05 +00:00
# Author: Nic Wolfe <nic@wolfeden.ca>
# URL: http://code.google.com/p/sickbeard/
#
2014-11-12 16:43:14 +00:00
# This file is part of SickGear.
2014-03-10 05:18:05 +00:00
#
2014-11-12 16:43:14 +00:00
# SickGear is free software: you can redistribute it and/or modify
2014-03-10 05:18:05 +00:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
2014-11-12 16:43:14 +00:00
# SickGear is distributed in the hope that it will be useful,
2014-03-10 05:18:05 +00:00
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
2014-11-12 16:43:14 +00:00
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
2014-03-10 05:18:05 +00:00
import datetime
import sickbeard
import os . path
2015-06-05 09:44:43 +00:00
from sickbeard import db , common , logger
2014-03-10 05:18:05 +00:00
from sickbeard import encodingKludge as ek
2014-07-06 13:11:04 +00:00
from sickbeard . name_parser . parser import NameParser , InvalidNameException , InvalidShowException
2014-03-10 05:18:05 +00:00
2014-03-25 05:57:24 +00:00
MIN_DB_VERSION = 9 # oldest db version we support migrating from
2016-09-04 20:00:44 +00:00
MAX_DB_VERSION = 20004
2014-12-09 12:30:00 +00:00
2014-05-20 19:02:10 +00:00
2014-03-25 05:57:24 +00:00
class MainSanityCheck ( db . DBSanityCheck ) :
2014-03-10 05:18:05 +00:00
def check ( self ) :
2014-04-22 18:32:45 +00:00
self . fix_missing_table_indexes ( )
2014-03-10 05:18:05 +00:00
self . fix_duplicate_shows ( )
self . fix_duplicate_episodes ( )
self . fix_orphan_episodes ( )
2014-05-18 17:12:12 +00:00
self . fix_unaired_episodes ( )
2017-07-11 09:29:55 +00:00
self . fix_scene_exceptions ( )
2014-03-10 05:18:05 +00:00
2014-05-06 22:54:04 +00:00
def fix_duplicate_shows ( self , column = ' indexer_id ' ) :
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
sql_results = self . connection . select (
' SELECT show_id, ' + column + ' , COUNT( ' + column + ' ) as count FROM tv_shows GROUP BY ' + column + ' HAVING count > 1 ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
for cur_duplicate in sql_results :
2014-03-10 05:18:05 +00:00
2016-09-27 20:18:58 +00:00
logger . log ( u ' Duplicate show detected! %s : %s count: %s ' % ( column , cur_duplicate [ column ] ,
cur_duplicate [ ' count ' ] ) , logger . DEBUG )
2014-03-10 05:18:05 +00:00
2014-03-25 05:57:24 +00:00
cur_dupe_results = self . connection . select (
2014-12-13 05:04:21 +00:00
' SELECT show_id, ' + column + ' FROM tv_shows WHERE ' + column + ' = ? LIMIT ? ' ,
[ cur_duplicate [ column ] , int ( cur_duplicate [ ' count ' ] ) - 1 ]
2014-03-25 05:57:24 +00:00
)
2014-03-10 05:18:05 +00:00
2016-09-27 20:18:58 +00:00
cl = [ ]
2014-03-10 05:18:05 +00:00
for cur_dupe_id in cur_dupe_results :
2014-03-25 05:57:24 +00:00
logger . log (
2016-09-27 20:18:58 +00:00
u ' Deleting duplicate show with %s : %s show_id: %s ' % ( column , cur_dupe_id [ column ] ,
cur_dupe_id [ ' show_id ' ] ) )
cl . append ( [ ' DELETE FROM tv_shows WHERE show_id = ? ' , [ cur_dupe_id [ ' show_id ' ] ] ] )
if 0 < len ( cl ) :
self . connection . mass_action ( cl )
2014-03-10 05:18:05 +00:00
else :
2014-12-13 05:04:21 +00:00
logger . log ( u ' No duplicate show, check passed ' )
2014-03-10 05:18:05 +00:00
def fix_duplicate_episodes ( self ) :
2014-12-13 05:04:21 +00:00
sql_results = self . connection . select (
' SELECT showid, season, episode, COUNT(showid) as count FROM tv_episodes GROUP BY showid, season, episode HAVING count > 1 ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
for cur_duplicate in sql_results :
2014-03-10 05:18:05 +00:00
2016-09-27 20:18:58 +00:00
logger . log ( u ' Duplicate episode detected! showid: %s season: %s episode: %s count: %s ' %
( cur_duplicate [ ' showid ' ] , cur_duplicate [ ' season ' ] , cur_duplicate [ ' episode ' ] ,
cur_duplicate [ ' count ' ] ) , logger . DEBUG )
2014-03-10 05:18:05 +00:00
2014-03-25 05:57:24 +00:00
cur_dupe_results = self . connection . select (
2014-12-13 05:04:21 +00:00
' SELECT episode_id FROM tv_episodes WHERE showid = ? AND season = ? and episode = ? ORDER BY episode_id DESC LIMIT ? ' ,
[ cur_duplicate [ ' showid ' ] , cur_duplicate [ ' season ' ] , cur_duplicate [ ' episode ' ] ,
int ( cur_duplicate [ ' count ' ] ) - 1 ]
2014-03-25 05:57:24 +00:00
)
2014-03-10 05:18:05 +00:00
2016-09-27 20:18:58 +00:00
cl = [ ]
2014-03-10 05:18:05 +00:00
for cur_dupe_id in cur_dupe_results :
2016-09-27 20:18:58 +00:00
logger . log ( u ' Deleting duplicate episode with episode_id: %s ' % cur_dupe_id [ ' episode_id ' ] )
cl . append ( [ ' DELETE FROM tv_episodes WHERE episode_id = ? ' , [ cur_dupe_id [ ' episode_id ' ] ] ] )
if 0 < len ( cl ) :
self . connection . mass_action ( cl )
2014-03-10 05:18:05 +00:00
else :
2014-12-13 05:04:21 +00:00
logger . log ( u ' No duplicate episode, check passed ' )
2014-03-10 05:18:05 +00:00
def fix_orphan_episodes ( self ) :
2014-12-13 05:04:21 +00:00
sql_results = self . connection . select (
' SELECT episode_id, showid, tv_shows.indexer_id FROM tv_episodes LEFT JOIN tv_shows ON tv_episodes.showid=tv_shows.indexer_id WHERE tv_shows.indexer_id is NULL ' )
2014-03-10 05:18:05 +00:00
2016-09-27 20:18:58 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
for cur_orphan in sql_results :
2016-09-27 20:18:58 +00:00
logger . log ( u ' Orphan episode detected! episode_id: %s showid: %s ' % ( cur_orphan [ ' episode_id ' ] ,
cur_orphan [ ' showid ' ] ) , logger . DEBUG )
logger . log ( u ' Deleting orphan episode with episode_id: %s ' % cur_orphan [ ' episode_id ' ] )
cl . append ( [ ' DELETE FROM tv_episodes WHERE episode_id = ? ' , [ cur_orphan [ ' episode_id ' ] ] ] )
if 0 < len ( cl ) :
self . connection . mass_action ( cl )
2014-03-10 05:18:05 +00:00
else :
2014-12-13 05:04:21 +00:00
logger . log ( u ' No orphan episodes, check passed ' )
2014-03-10 05:18:05 +00:00
2014-04-22 18:32:45 +00:00
def fix_missing_table_indexes ( self ) :
2014-12-13 05:04:21 +00:00
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); ' )
2014-04-22 18:32:45 +00:00
2014-12-13 05:04:21 +00:00
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); ' )
2014-04-22 18:32:45 +00:00
2014-12-13 05:04:21 +00:00
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); ' )
2014-03-25 05:57:24 +00:00
2014-12-13 05:04:21 +00:00
if not self . connection . select ( ' PRAGMA index_info( " idx_status " ) ' ) :
logger . log ( u ' Missing idx_status for TV Episodes table detected!, fixing... ' )
self . connection . action ( ' CREATE INDEX idx_status ON tv_episodes (status,season,episode,airdate) ' )
2014-04-22 23:09:29 +00:00
2014-12-13 05:04:21 +00:00
if not self . connection . select ( ' PRAGMA index_info( " idx_sta_epi_air " ) ' ) :
logger . log ( u ' Missing idx_sta_epi_air for TV Episodes table detected!, fixing... ' )
self . connection . action ( ' CREATE INDEX idx_sta_epi_air ON tv_episodes (status,episode, airdate) ' )
2014-04-22 23:09:29 +00:00
2014-12-13 05:04:21 +00:00
if not self . connection . select ( ' PRAGMA index_info( " idx_sta_epi_sta_air " ) ' ) :
logger . log ( u ' Missing idx_sta_epi_sta_air for TV Episodes table detected!, fixing... ' )
self . connection . action ( ' CREATE INDEX idx_sta_epi_sta_air ON tv_episodes (season,episode, status, airdate) ' )
2014-04-22 23:09:29 +00:00
2014-05-18 17:12:12 +00:00
def fix_unaired_episodes ( self ) :
2016-09-27 20:18:58 +00:00
cur_date = datetime . date . today ( ) + datetime . timedelta ( days = 1 )
2014-05-18 17:12:12 +00:00
2014-12-13 05:04:21 +00:00
sql_results = self . connection . select (
2016-09-27 20:18:58 +00:00
' SELECT episode_id, showid FROM tv_episodes WHERE status = ? or ( airdate > ? AND status in (?,?) ) or '
' ( airdate <= 1 AND status = ? ) ' , [ ' ' , cur_date . toordinal ( ) , common . SKIPPED , common . WANTED , common . WANTED ] )
2014-05-18 17:12:12 +00:00
2016-09-27 20:18:58 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
for cur_unaired in sql_results :
2016-09-27 20:18:58 +00:00
logger . log ( u ' UNAIRED episode detected! episode_id: %s showid: %s ' % ( cur_unaired [ ' episode_id ' ] ,
cur_unaired [ ' showid ' ] ) , logger . DEBUG )
logger . log ( u ' Fixing unaired episode status with episode_id: %s ' % cur_unaired [ ' episode_id ' ] )
cl . append ( [ ' UPDATE tv_episodes SET status = ? WHERE episode_id = ? ' ,
[ common . UNAIRED , cur_unaired [ ' episode_id ' ] ] ] )
if 0 < len ( cl ) :
self . connection . mass_action ( cl )
2014-05-18 17:12:12 +00:00
else :
2014-12-13 05:04:21 +00:00
logger . log ( u ' No UNAIRED episodes, check passed ' )
2014-05-18 17:12:12 +00:00
2017-07-11 09:29:55 +00:00
def fix_scene_exceptions ( self ) :
sql_results = self . connection . select (
' SELECT exception_id FROM scene_exceptions WHERE season = " null " ' )
if 0 < len ( sql_results ) :
logger . log ( ' Fixing invalid scene exceptions ' )
self . connection . action ( ' UPDATE scene_exceptions SET season = -1 WHERE season = " null " ' )
2014-05-18 17:12:12 +00:00
2014-03-10 05:18:05 +00:00
# ======================
# = Main DB Migrations =
# ======================
# Add new migrations at the bottom of the list; subclass the previous migration.
2015-06-05 09:44:43 +00:00
# 0 -> 20003
2014-12-09 12:30:00 +00:00
class InitialSchema ( db . SchemaUpgrade ) :
2014-03-10 05:18:05 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-09 12:30:00 +00:00
2014-12-13 05:04:21 +00:00
if not self . hasTable ( ' tv_shows ' ) and not self . hasTable ( ' db_version ' ) :
2014-03-10 05:18:05 +00:00
queries = [
2015-06-05 09:44:43 +00:00
# original sick beard tables
2014-12-13 05:04:21 +00:00
' CREATE TABLE db_version (db_version INTEGER); ' ,
2015-06-05 09:44:43 +00:00
' CREATE TABLE history (action NUMERIC, date NUMERIC, showid NUMERIC, season NUMERIC, episode NUMERIC, quality NUMERIC, resource TEXT, provider TEXT, version NUMERIC) ' ,
2014-12-13 05:04:21 +00:00
' CREATE TABLE info (last_backlog NUMERIC, last_indexer NUMERIC, last_proper_search NUMERIC) ' ,
2015-06-05 09:44:43 +00:00
' CREATE TABLE tv_episodes (episode_id INTEGER PRIMARY KEY, showid NUMERIC, indexerid NUMERIC, indexer NUMERIC, name TEXT, season NUMERIC, episode NUMERIC, description TEXT, airdate NUMERIC, hasnfo NUMERIC, hastbn NUMERIC, status NUMERIC, location TEXT, file_size NUMERIC, release_name TEXT, subtitles TEXT, subtitles_searchcount NUMERIC, subtitles_lastsearch TIMESTAMP, is_proper NUMERIC, scene_season NUMERIC, scene_episode NUMERIC, absolute_number NUMERIC, scene_absolute_number NUMERIC, version NUMERIC, release_group TEXT, trakt_watched NUMERIC) ' ,
' CREATE TABLE tv_shows (show_id INTEGER PRIMARY KEY, indexer_id NUMERIC, indexer NUMERIC, show_name TEXT, location TEXT, network TEXT, genre TEXT, classification TEXT, runtime NUMERIC, quality NUMERIC, airs TEXT, status TEXT, flatten_folders NUMERIC, paused NUMERIC, startyear NUMERIC, air_by_date NUMERIC, lang TEXT, subtitles NUMERIC, notify_list TEXT, imdb_id TEXT, last_update_indexer NUMERIC, dvdorder NUMERIC, archive_firstmatch NUMERIC, rls_require_words TEXT, rls_ignore_words TEXT, sports NUMERIC, anime NUMERIC, scene NUMERIC, overview TEXT, tag TEXT) ' ,
' CREATE INDEX idx_showid ON tv_episodes (showid) ' ,
' CREATE INDEX idx_tv_episodes_showid_airdate ON tv_episodes (showid,airdate) ' ,
' CREATE TABLE blacklist (show_id INTEGER, range TEXT, keyword TEXT) ' ,
' CREATE TABLE indexer_mapping (indexer_id INTEGER, indexer NUMERIC, mindexer_id INTEGER, mindexer NUMERIC, PRIMARY KEY (indexer_id, indexer)) ' ,
' CREATE TABLE imdb_info (indexer_id INTEGER PRIMARY KEY, imdb_id TEXT, title TEXT, year NUMERIC, akas TEXT, runtimes NUMERIC, genres TEXT, countries TEXT, country_codes TEXT, certificates TEXT, rating TEXT, votes INTEGER, last_update NUMERIC) ' ,
' CREATE TABLE scene_numbering (indexer TEXT, indexer_id INTEGER, season INTEGER, episode INTEGER, scene_season INTEGER, scene_episode INTEGER, absolute_number NUMERIC, scene_absolute_number NUMERIC, PRIMARY KEY (indexer_id, season, episode)) ' ,
' CREATE TABLE whitelist (show_id INTEGER, range TEXT, keyword TEXT) ' ,
' CREATE TABLE xem_refresh (indexer TEXT, indexer_id INTEGER PRIMARY KEY, last_refreshed INTEGER) ' ,
2014-12-13 05:04:21 +00:00
' CREATE UNIQUE INDEX idx_indexer_id ON tv_shows (indexer_id) ' ,
2015-06-05 09:44:43 +00:00
' CREATE INDEX idx_sta_epi_air ON tv_episodes (status,episode, airdate) ' ,
' CREATE INDEX idx_sta_epi_sta_air ON tv_episodes (season,episode, status, airdate) ' ,
' CREATE INDEX idx_status ON tv_episodes (status,season,episode,airdate) ' ,
' INSERT INTO db_version (db_version) VALUES (20003) '
2014-03-25 05:57:24 +00:00
]
2014-03-10 05:18:05 +00:00
for query in queries :
self . connection . action ( query )
else :
cur_db_version = self . checkDBVersion ( )
if cur_db_version < MIN_DB_VERSION :
2014-12-13 05:04:21 +00:00
logger . log_error_and_exit ( u ' Your database version ( '
+ str ( cur_db_version )
+ ' ) is too old to migrate from what this version of SickGear supports ( '
+ str ( MIN_DB_VERSION ) + ' ). ' + " \n "
+ ' Upgrade using a previous version (tag) build 496 to build 501 of SickGear first or remove database file to begin fresh. '
)
2014-03-10 05:18:05 +00:00
if cur_db_version > MAX_DB_VERSION :
2014-12-13 05:04:21 +00:00
logger . log_error_and_exit ( u ' Your database version ( '
+ str ( cur_db_version )
+ ' ) has been incremented past what this version of SickGear supports ( '
+ str ( MAX_DB_VERSION ) + ' ). ' + " \n "
+ ' If you have used other forks of SickGear, your database may be unusable due to their modifications. '
)
2014-03-10 05:18:05 +00:00
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2014-12-09 12:30:00 +00:00
# 9 -> 10
class AddSizeAndSceneNameFields ( db . SchemaUpgrade ) :
2014-03-10 05:18:05 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_episodes ' , ' file_size ' ) :
self . addColumn ( ' tv_episodes ' , ' file_size ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_episodes ' , ' release_name ' ) :
self . addColumn ( ' tv_episodes ' , ' release_name ' , ' TEXT ' , ' ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
ep_results = self . connection . select ( ' SELECT episode_id, location, file_size FROM tv_episodes ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding file size to all episodes in DB, please be patient ' )
2014-03-10 05:18:05 +00:00
for cur_ep in ep_results :
2014-12-13 05:04:21 +00:00
if not cur_ep [ ' location ' ] :
2014-03-10 05:18:05 +00:00
continue
# if there is no size yet then populate it for us
2014-12-13 05:04:21 +00:00
if ( not cur_ep [ ' file_size ' ] or not int ( cur_ep [ ' file_size ' ] ) ) and ek . ek ( os . path . isfile , cur_ep [ ' location ' ] ) :
cur_size = ek . ek ( os . path . getsize , cur_ep [ ' location ' ] )
self . connection . action ( ' UPDATE tv_episodes SET file_size = ? WHERE episode_id = ? ' ,
[ cur_size , int ( cur_ep [ ' episode_id ' ] ) ] )
2014-03-10 05:18:05 +00:00
# check each snatch to see if we can use it to get a release name from
2014-12-13 05:04:21 +00:00
history_results = self . connection . select ( ' SELECT * FROM history WHERE provider != -1 ORDER BY date ASC ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding release name to all episodes still in history ' )
2014-03-10 05:18:05 +00:00
for cur_result in history_results :
# find the associated download, if there isn't one then ignore it
2014-03-25 05:57:24 +00:00
download_results = self . connection . select (
2014-12-13 05:04:21 +00:00
' SELECT resource FROM history WHERE provider = -1 AND showid = ? AND season = ? AND episode = ? AND date > ? ' ,
[ cur_result [ ' showid ' ] , cur_result [ ' season ' ] , cur_result [ ' episode ' ] , cur_result [ ' date ' ] ] )
2014-03-10 05:18:05 +00:00
if not download_results :
2014-12-13 05:04:21 +00:00
logger . log ( u ' Found a snatch in the history for ' + cur_result [
' resource ' ] + ' but couldn \' t find the associated download, skipping it ' , logger . DEBUG )
2014-03-10 05:18:05 +00:00
continue
2014-12-13 05:04:21 +00:00
nzb_name = cur_result [ ' resource ' ]
file_name = ek . ek ( os . path . basename , download_results [ 0 ] [ ' resource ' ] )
2014-03-10 05:18:05 +00:00
# take the extension off the filename, it's not needed
if ' . ' in file_name :
file_name = file_name . rpartition ( ' . ' ) [ 0 ]
# find the associated episode on disk
2014-03-25 05:57:24 +00:00
ep_results = self . connection . select (
2014-12-13 05:04:21 +00:00
' SELECT episode_id, status FROM tv_episodes WHERE showid = ? AND season = ? AND episode = ? AND location != " " ' ,
[ cur_result [ ' showid ' ] , cur_result [ ' season ' ] , cur_result [ ' episode ' ] ] )
2014-03-10 05:18:05 +00:00
if not ep_results :
2014-03-25 05:57:24 +00:00
logger . log (
2014-12-13 05:04:21 +00:00
u ' The episode ' + nzb_name + ' was found in history but doesn \' t exist on disk anymore, skipping ' ,
2014-03-25 05:57:24 +00:00
logger . DEBUG )
2014-03-10 05:18:05 +00:00
continue
# get the status/quality of the existing ep and make sure it's what we expect
2014-12-13 05:04:21 +00:00
ep_status , ep_quality = common . Quality . splitCompositeStatus ( int ( ep_results [ 0 ] [ ' status ' ] ) )
2014-03-10 05:18:05 +00:00
if ep_status != common . DOWNLOADED :
continue
2014-12-13 05:04:21 +00:00
if ep_quality != int ( cur_result [ ' quality ' ] ) :
2014-03-10 05:18:05 +00:00
continue
# make sure this is actually a real release name and not a season pack or something
for cur_name in ( nzb_name , file_name ) :
2014-12-13 05:04:21 +00:00
logger . log ( u ' Checking if ' + cur_name + ' is actually a good release name ' , logger . DEBUG )
2014-03-10 05:18:05 +00:00
try :
np = NameParser ( False )
parse_result = np . parse ( cur_name )
2014-07-06 13:11:04 +00:00
except ( InvalidNameException , InvalidShowException ) :
2014-03-10 05:18:05 +00:00
continue
2014-12-13 05:04:21 +00:00
if parse_result . series_name and parse_result . season_number is not None \
and parse_result . episode_numbers and parse_result . release_group :
2014-03-10 05:18:05 +00:00
# if all is well by this point we'll just put the release name into the database
2014-12-13 05:04:21 +00:00
self . connection . action ( ' UPDATE tv_episodes SET release_name = ? WHERE episode_id = ? ' ,
[ cur_name , ep_results [ 0 ] [ ' episode_id ' ] ] )
2014-03-10 05:18:05 +00:00
break
# check each snatch to see if we can use it to get a release name from
2014-12-13 05:04:21 +00:00
empty_results = self . connection . select ( ' SELECT episode_id, location FROM tv_episodes WHERE release_name = " " ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding release name to all episodes with obvious scene filenames ' )
2014-03-10 05:18:05 +00:00
for cur_result in empty_results :
2014-12-13 05:04:21 +00:00
ep_file_name = ek . ek ( os . path . basename , cur_result [ ' location ' ] )
2014-03-10 05:18:05 +00:00
ep_file_name = os . path . splitext ( ep_file_name ) [ 0 ]
# only want to find real scene names here so anything with a space in it is out
if ' ' in ep_file_name :
continue
try :
np = NameParser ( False )
parse_result = np . parse ( ep_file_name )
2014-07-06 13:11:04 +00:00
except ( InvalidNameException , InvalidShowException ) :
2014-03-10 05:18:05 +00:00
continue
if not parse_result . release_group :
continue
2014-03-25 05:57:24 +00:00
logger . log (
2014-12-13 05:04:21 +00:00
u ' Name ' + ep_file_name + ' gave release group of ' + parse_result . release_group + ' , seems valid ' ,
2014-03-25 05:57:24 +00:00
logger . DEBUG )
2014-12-13 05:04:21 +00:00
self . connection . action ( ' UPDATE tv_episodes SET release_name = ? WHERE episode_id = ? ' ,
[ ep_file_name , cur_result [ ' episode_id ' ] ] )
2014-03-10 05:18:05 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2014-12-09 12:30:00 +00:00
# 10 -> 11
class RenameSeasonFolders ( db . SchemaUpgrade ) :
2014-03-10 05:18:05 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-09 12:30:00 +00:00
2014-03-10 05:18:05 +00:00
# rename the column
2014-12-13 05:04:21 +00:00
self . connection . action ( ' ALTER TABLE tv_shows RENAME TO tmp_tv_shows ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' CREATE TABLE tv_shows (show_id INTEGER PRIMARY KEY, location TEXT, show_name TEXT, tvdb_id NUMERIC, network TEXT, genre TEXT, runtime NUMERIC, quality NUMERIC, airs TEXT, status TEXT, flatten_folders NUMERIC, paused NUMERIC, startyear NUMERIC, tvr_id NUMERIC, tvr_name TEXT, air_by_date NUMERIC, lang TEXT) ' )
sql = ' INSERT INTO tv_shows(show_id, location, show_name, tvdb_id, network, genre, runtime, quality, airs, status, flatten_folders, paused, startyear, tvr_id, tvr_name, air_by_date, lang) SELECT show_id, location, show_name, tvdb_id, network, genre, runtime, quality, airs, status, seasonfolders, paused, startyear, tvr_id, tvr_name, air_by_date, lang FROM tmp_tv_shows '
2014-03-10 05:18:05 +00:00
self . connection . action ( sql )
# flip the values to be opposite of what they were before
2014-12-13 05:04:21 +00:00
self . connection . action ( ' UPDATE tv_shows SET flatten_folders = 2 WHERE flatten_folders = 1 ' )
self . connection . action ( ' UPDATE tv_shows SET flatten_folders = 1 WHERE flatten_folders = 0 ' )
self . connection . action ( ' UPDATE tv_shows SET flatten_folders = 0 WHERE flatten_folders = 2 ' )
self . connection . action ( ' DROP TABLE tmp_tv_shows ' )
2014-03-10 05:18:05 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 11 -> 12
class Add1080pAndRawHDQualities ( db . SchemaUpgrade ) :
2014-12-13 05:04:21 +00:00
"""
Add support for 1080 p related qualities along with RawHD
2014-03-10 05:18:05 +00:00
Quick overview of what the upgrade needs to do :
quality | old | new
- - - - - - - - - - - - - - - - - - - - - - - - - -
hdwebdl | 1 << 3 | 1 << 5
hdbluray | 1 << 4 | 1 << 7
fullhdbluray | 1 << 5 | 1 << 8
- - - - - - - - - - - - - - - - - - - - - - - - - -
rawhdtv | | 1 << 3
fullhdtv | | 1 << 4
fullhdwebdl | | 1 << 6
"""
def _update_status ( self , old_status ) :
( status , quality ) = common . Quality . splitCompositeStatus ( old_status )
return common . Quality . compositeStatus ( status , self . _update_quality ( quality ) )
def _update_quality ( self , old_quality ) :
2014-12-13 05:04:21 +00:00
"""
Update bitwise flags to reflect new quality values
2014-03-10 05:18:05 +00:00
Check flag bits ( clear old then set their new locations ) starting
with the highest bits so we dont overwrite data we need later on
"""
result = old_quality
# move fullhdbluray from 1<<5 to 1<<8 if set
2014-12-13 05:04:21 +00:00
if result & ( 1 << 5 ) :
result & = ~ ( 1 << 5 )
result | = 1 << 8
2014-03-10 05:18:05 +00:00
# move hdbluray from 1<<4 to 1<<7 if set
2014-12-13 05:04:21 +00:00
if result & ( 1 << 4 ) :
result & = ~ ( 1 << 4 )
result | = 1 << 7
2014-03-10 05:18:05 +00:00
# move hdwebdl from 1<<3 to 1<<5 if set
2014-12-13 05:04:21 +00:00
if result & ( 1 << 3 ) :
result & = ~ ( 1 << 3 )
result | = 1 << 5
2014-03-10 05:18:05 +00:00
return result
def _update_composite_qualities ( self , status ) :
2014-12-13 05:04:21 +00:00
'''
Unpack , Update , Return new quality values
2014-03-10 05:18:05 +00:00
Unpack the composite archive / initial values .
Update either qualities if needed .
Then return the new compsite quality value .
2014-12-13 05:04:21 +00:00
'''
2014-03-10 05:18:05 +00:00
best = ( status & ( 0xffff << 16 ) ) >> 16
2014-12-13 05:04:21 +00:00
initial = status & 0xffff
2014-03-10 05:18:05 +00:00
best = self . _update_quality ( best )
initial = self . _update_quality ( initial )
result = ( ( best << 16 ) | initial )
return result
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-10 05:18:05 +00:00
# update the default quality so we dont grab the wrong qualities after migration
sickbeard . QUALITY_DEFAULT = self . _update_composite_qualities ( sickbeard . QUALITY_DEFAULT )
sickbeard . save_config ( )
# upgrade previous HD to HD720p -- shift previous qualities to new placevalues
2014-03-25 05:57:24 +00:00
old_hd = common . Quality . combineQualities (
[ common . Quality . HDTV , common . Quality . HDWEBDL >> 2 , common . Quality . HDBLURAY >> 3 ] , [ ] )
2014-12-13 05:04:21 +00:00
new_hd = common . Quality . combineQualities ( [ common . Quality . HDTV , common . Quality . HDWEBDL ,
common . Quality . HDBLURAY ] , [ ] )
2014-03-10 05:18:05 +00:00
# update ANY -- shift existing qualities and add new 1080p qualities, note that rawHD was not added to the ANY template
2014-03-25 05:57:24 +00:00
old_any = common . Quality . combineQualities (
[ common . Quality . SDTV , common . Quality . SDDVD , common . Quality . HDTV , common . Quality . HDWEBDL >> 2 ,
common . Quality . HDBLURAY >> 3 , common . Quality . UNKNOWN ] , [ ] )
new_any = common . Quality . combineQualities (
[ common . Quality . SDTV , common . Quality . SDDVD , common . Quality . HDTV , common . Quality . FULLHDTV ,
common . Quality . HDWEBDL , common . Quality . FULLHDWEBDL , common . Quality . HDBLURAY , common . Quality . FULLHDBLURAY ,
common . Quality . UNKNOWN ] , [ ] )
2014-03-10 05:18:05 +00:00
# update qualities (including templates)
2014-12-13 05:04:21 +00:00
logger . log ( u ' [1/4] Updating pre-defined templates and the quality for each show... ' , logger . MESSAGE )
2014-07-15 02:00:53 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
shows = self . connection . select ( ' SELECT * FROM tv_shows ' )
2014-03-10 05:18:05 +00:00
for cur_show in shows :
2014-12-13 05:04:21 +00:00
if old_hd == cur_show [ ' quality ' ] :
2014-03-10 05:18:05 +00:00
new_quality = new_hd
2014-12-13 05:04:21 +00:00
elif old_any == cur_show [ ' quality ' ] :
2014-03-10 05:18:05 +00:00
new_quality = new_any
else :
2014-12-13 05:04:21 +00:00
new_quality = self . _update_composite_qualities ( cur_show [ ' quality ' ] )
cl . append ( [ ' UPDATE tv_shows SET quality = ? WHERE show_id = ? ' , [ new_quality , cur_show [ ' show_id ' ] ] ] )
2014-07-15 02:00:53 +00:00
self . connection . mass_action ( cl )
2014-03-10 05:18:05 +00:00
# update status that are are within the old hdwebdl (1<<3 which is 8) and better -- exclude unknown (1<<15 which is 32768)
2014-12-13 05:04:21 +00:00
logger . log ( u ' [2/4] Updating the status for the episodes within each show... ' , logger . MESSAGE )
2014-07-15 02:00:53 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
episodes = self . connection . select ( ' SELECT * FROM tv_episodes WHERE status < 3276800 AND status >= 800 ' )
2014-03-10 05:18:05 +00:00
for cur_episode in episodes :
2014-12-13 05:04:21 +00:00
cl . append ( [ ' UPDATE tv_episodes SET status = ? WHERE episode_id = ? ' ,
[ self . _update_status ( cur_episode [ ' status ' ] ) , cur_episode [ ' episode_id ' ] ] ] )
2014-07-15 02:00:53 +00:00
self . connection . mass_action ( cl )
2014-03-10 05:18:05 +00:00
# make two seperate passes through the history since snatched and downloaded (action & quality) may not always coordinate together
# update previous history so it shows the correct action
2014-12-13 05:04:21 +00:00
logger . log ( u ' [3/4] Updating history to reflect the correct action... ' , logger . MESSAGE )
2014-07-15 02:00:53 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
history_action = self . connection . select ( ' SELECT * FROM history WHERE action < 3276800 AND action >= 800 ' )
for cur_entry in history_action :
cl . append ( [ ' UPDATE history SET action = ? WHERE showid = ? AND date = ? ' ,
[ self . _update_status ( cur_entry [ ' action ' ] ) , cur_entry [ ' showid ' ] , cur_entry [ ' date ' ] ] ] )
2014-07-15 02:00:53 +00:00
self . connection . mass_action ( cl )
2014-03-10 05:18:05 +00:00
# update previous history so it shows the correct quality
2014-12-13 05:04:21 +00:00
logger . log ( u ' [4/4] Updating history to reflect the correct quality... ' , logger . MESSAGE )
2014-07-15 02:00:53 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
history_quality = self . connection . select ( ' SELECT * FROM history WHERE quality < 32768 AND quality >= 8 ' )
for cur_entry in history_quality :
cl . append ( [ ' UPDATE history SET quality = ? WHERE showid = ? AND date = ? ' ,
[ self . _update_quality ( cur_entry [ ' quality ' ] ) , cur_entry [ ' showid ' ] , cur_entry [ ' date ' ] ] ] )
2014-07-15 02:00:53 +00:00
self . connection . mass_action ( cl )
2014-03-10 05:18:05 +00:00
self . incDBVersion ( )
# cleanup and reduce db if any previous data was removed
2014-12-13 05:04:21 +00:00
logger . log ( u ' Performing a vacuum on the database. ' , logger . DEBUG )
self . connection . action ( ' VACUUM ' )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 12 -> 13
class AddShowidTvdbidIndex ( db . SchemaUpgrade ) :
2014-12-13 05:04:21 +00:00
# Adding index on tvdb_id (tv_shows) and showid (tv_episodes) to speed up searches/queries
2014-03-10 05:18:05 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-10 05:18:05 +00:00
2015-02-08 02:59:10 +00:00
logger . log ( u ' Checking for duplicate shows before adding unique index. ' )
2014-05-06 22:54:04 +00:00
MainSanityCheck ( self . connection ) . fix_duplicate_shows ( ' tvdb_id ' )
2014-03-10 05:18:05 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding index on tvdb_id (tv_shows) and showid (tv_episodes) to speed up searches/queries. ' )
if not self . hasTable ( ' idx_showid ' ) :
self . connection . action ( ' CREATE INDEX idx_showid ON tv_episodes (showid); ' )
if not self . hasTable ( ' idx_tvdb_id ' ) :
self . connection . action ( ' CREATE UNIQUE INDEX idx_tvdb_id ON tv_shows (tvdb_id); ' )
2014-03-10 05:18:05 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 13 -> 14
class AddLastUpdateTVDB ( db . SchemaUpgrade ) :
2014-12-13 05:04:21 +00:00
# Adding column last_update_tvdb to tv_shows for controlling nightly updates
2014-03-10 05:18:05 +00:00
def execute ( self ) :
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' last_update_tvdb ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding column last_update_tvdb to tv_shows ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' last_update_tvdb ' , default = 1 )
2014-03-10 05:18:05 +00:00
self . incDBVersion ( )
2015-03-27 19:25:34 +00:00
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2014-03-25 05:57:24 +00:00
2014-12-09 12:30:00 +00:00
# 14 -> 15
class AddDBIncreaseTo15 ( db . SchemaUpgrade ) :
2014-03-10 05:18:05 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-07 00:03:55 +00:00
2015-03-27 19:25:34 +00:00
logger . log ( u ' Bumping database version to v %s ' % self . checkDBVersion ( ) )
2014-12-09 12:30:00 +00:00
self . incDBVersion ( )
return self . checkDBVersion ( )
2014-05-20 19:02:10 +00:00
2014-05-07 00:03:55 +00:00
2014-12-09 12:30:00 +00:00
# 15 -> 16
class AddIMDbInfo ( db . SchemaUpgrade ) :
2014-05-07 00:03:55 +00:00
def execute ( self ) :
2014-12-09 12:30:00 +00:00
2016-12-09 15:41:49 +00:00
db_backed_up = False
if not self . hasTable ( ' imdb_info ' ) :
logger . log ( u ' Creating IMDb table imdb_info ' )
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
db_backed_up = True
self . connection . action (
' CREATE TABLE imdb_info (tvdb_id INTEGER PRIMARY KEY, imdb_id TEXT, title TEXT, year NUMERIC, akas TEXT, runtimes NUMERIC, genres TEXT, countries TEXT, country_codes TEXT, certificates TEXT, rating TEXT, votes INTEGER, last_update NUMERIC) ' )
2014-05-07 00:49:03 +00:00
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' imdb_id ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding IMDb column imdb_id to tv_shows ' )
2016-12-09 15:41:49 +00:00
if not db_backed_up :
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' imdb_id ' )
2014-05-07 00:49:03 +00:00
2014-05-07 00:03:55 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-07 00:03:55 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 16 -> 17
class AddProperNamingSupport ( db . SchemaUpgrade ) :
2014-05-07 00:03:55 +00:00
def execute ( self ) :
2014-12-09 12:30:00 +00:00
2015-03-27 19:25:34 +00:00
if not self . hasColumn ( ' tv_shows ' , ' imdb_id ' ) \
and self . hasColumn ( ' tv_shows ' , ' rls_require_words ' ) \
and self . hasColumn ( ' tv_shows ' , ' rls_ignore_words ' ) :
self . setDBVersion ( 5816 )
return self . checkDBVersion ( )
if not self . hasColumn ( ' tv_episodes ' , ' is_proper ' ) :
logger . log ( u ' Adding column is_proper to tv_episodes ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2015-03-27 19:25:34 +00:00
self . addColumn ( ' tv_episodes ' , ' is_proper ' )
2014-05-07 00:03:55 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-07 00:03:55 +00:00
2014-12-09 12:30:00 +00:00
# 17 -> 18
class AddEmailSubscriptionTable ( db . SchemaUpgrade ) :
2014-05-07 00:03:55 +00:00
def execute ( self ) :
2014-12-09 12:30:00 +00:00
2015-03-27 19:25:34 +00:00
if not self . hasColumn ( ' tv_episodes ' , ' is_proper ' ) \
and self . hasColumn ( ' tv_shows ' , ' rls_require_words ' ) \
and self . hasColumn ( ' tv_shows ' , ' rls_ignore_words ' ) \
and self . hasColumn ( ' tv_shows ' , ' skip_notices ' ) :
self . setDBVersion ( 5817 )
return self . checkDBVersion ( )
if not self . hasColumn ( ' tv_shows ' , ' notify_list ' ) :
logger . log ( u ' Adding column notify_list to tv_shows ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2015-03-27 19:25:34 +00:00
self . addColumn ( ' tv_shows ' , ' notify_list ' , ' TEXT ' , None )
2014-05-07 00:03:55 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-07 00:03:55 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 18 -> 19
class AddProperSearch ( db . SchemaUpgrade ) :
2014-05-07 00:03:55 +00:00
def execute ( self ) :
2016-12-09 15:41:49 +00:00
if not self . hasColumn ( ' tv_episodes ' , ' is_proper ' ) :
self . setDBVersion ( 12 )
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2015-03-27 19:25:34 +00:00
if not self . hasColumn ( ' tv_shows ' , ' notify_list ' ) \
and self . hasColumn ( ' tv_shows ' , ' rls_require_words ' ) \
and self . hasColumn ( ' tv_shows ' , ' rls_ignore_words ' ) \
and self . hasColumn ( ' tv_shows ' , ' skip_notices ' ) \
and self . hasColumn ( ' history ' , ' source ' ) :
self . setDBVersion ( 5818 )
return self . checkDBVersion ( )
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' info ' , ' last_proper_search ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding column last_proper_search to info ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' info ' , ' last_proper_search ' , default = 1 )
2014-03-10 05:18:05 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-10 05:18:05 +00:00
2014-03-25 05:57:24 +00:00
2014-12-09 12:30:00 +00:00
# 19 -> 20
class AddDvdOrderOption ( db . SchemaUpgrade ) :
2014-03-10 05:18:05 +00:00
def execute ( self ) :
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' dvdorder ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding column dvdorder to tv_shows ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' dvdorder ' , ' NUMERIC ' , ' 0 ' )
2014-03-11 18:23:20 +00:00
2014-03-11 19:28:44 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-11 16:35:13 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 20 -> 21
class AddSubtitlesSupport ( db . SchemaUpgrade ) :
2014-05-06 23:11:56 +00:00
def execute ( self ) :
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' subtitles ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding subtitles to tv_shows and tv_episodes ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' subtitles ' )
self . addColumn ( ' tv_episodes ' , ' subtitles ' , ' TEXT ' , ' ' )
self . addColumn ( ' tv_episodes ' , ' subtitles_searchcount ' )
self . addColumn ( ' tv_episodes ' , ' subtitles_lastsearch ' , ' TIMESTAMP ' , str ( datetime . datetime . min ) )
2015-03-27 19:25:34 +00:00
2014-05-06 23:11:56 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-06 23:11:56 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 21 -> 22
class ConvertTVShowsToIndexerScheme ( db . SchemaUpgrade ) :
2014-03-11 16:35:13 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-04-24 05:18:16 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Converting TV Shows table to Indexer Scheme... ' )
2014-04-22 17:56:19 +00:00
2014-12-13 05:04:21 +00:00
if self . hasTable ( ' tmp_tv_shows ' ) :
logger . log ( u ' Removing temp tv show tables left behind from previous updates... ' )
self . connection . action ( ' DROP TABLE tmp_tv_shows ' )
2014-04-22 17:52:14 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' ALTER TABLE tv_shows RENAME TO tmp_tv_shows ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' CREATE TABLE tv_shows (show_id INTEGER PRIMARY KEY, indexer_id NUMERIC, indexer NUMERIC, show_name TEXT, location TEXT, network TEXT, genre TEXT, classification TEXT, runtime NUMERIC, quality NUMERIC, airs TEXT, status TEXT, flatten_folders NUMERIC, paused NUMERIC, startyear NUMERIC, air_by_date NUMERIC, lang TEXT, subtitles NUMERIC, notify_list TEXT, imdb_id TEXT, last_update_indexer NUMERIC, dvdorder NUMERIC) ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' INSERT INTO tv_shows(show_id, indexer_id, show_name, location, network, genre, runtime, quality, airs, status, flatten_folders, paused, startyear, air_by_date, lang, subtitles, notify_list, imdb_id, last_update_indexer, dvdorder) SELECT show_id, tvdb_id, show_name, location, network, genre, runtime, quality, airs, status, flatten_folders, paused, startyear, air_by_date, lang, subtitles, notify_list, imdb_id, last_update_tvdb, dvdorder FROM tmp_tv_shows ' )
self . connection . action ( ' DROP TABLE tmp_tv_shows ' )
2014-03-11 18:23:20 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' CREATE UNIQUE INDEX idx_indexer_id ON tv_shows (indexer_id); ' )
2014-04-22 18:32:45 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' UPDATE tv_shows SET classification = " Scripted " ' )
self . connection . action ( ' UPDATE tv_shows SET indexer = 1 ' )
2014-04-22 23:09:29 +00:00
2014-03-11 19:52:00 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-11 19:52:00 +00:00
2014-03-25 05:57:24 +00:00
2014-12-09 12:30:00 +00:00
# 22 -> 23
class ConvertTVEpisodesToIndexerScheme ( db . SchemaUpgrade ) :
2014-03-11 18:23:20 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-11 18:23:20 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Converting TV Episodes table to Indexer Scheme... ' )
2014-04-22 17:56:19 +00:00
2014-12-13 05:04:21 +00:00
if self . hasTable ( ' tmp_tv_episodes ' ) :
logger . log ( u ' Removing temp tv episode tables left behind from previous updates... ' )
self . connection . action ( ' DROP TABLE tmp_tv_episodes ' )
2014-04-22 17:56:19 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' ALTER TABLE tv_episodes RENAME TO tmp_tv_episodes ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' CREATE TABLE tv_episodes (episode_id INTEGER PRIMARY KEY, showid NUMERIC, indexerid NUMERIC, indexer NUMERIC, name TEXT, season NUMERIC, episode NUMERIC, description TEXT, airdate NUMERIC, hasnfo NUMERIC, hastbn NUMERIC, status NUMERIC, location TEXT, file_size NUMERIC, release_name TEXT, subtitles TEXT, subtitles_searchcount NUMERIC, subtitles_lastsearch TIMESTAMP, is_proper NUMERIC) ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' INSERT INTO tv_episodes(episode_id, showid, indexerid, name, season, episode, description, airdate, hasnfo, hastbn, status, location, file_size, release_name, subtitles, subtitles_searchcount, subtitles_lastsearch, is_proper) SELECT episode_id, showid, tvdbid, name, season, episode, description, airdate, hasnfo, hastbn, status, location, file_size, release_name, subtitles, subtitles_searchcount, subtitles_lastsearch, is_proper FROM tmp_tv_episodes ' )
self . connection . action ( ' DROP TABLE tmp_tv_episodes ' )
2014-03-11 18:23:20 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' CREATE INDEX idx_tv_episodes_showid_airdate ON tv_episodes(showid,airdate); ' )
self . connection . action ( ' CREATE INDEX idx_showid ON tv_episodes (showid); ' )
self . connection . action ( ' CREATE INDEX idx_status ON tv_episodes (status,season,episode,airdate) ' )
self . connection . action ( ' CREATE INDEX idx_sta_epi_air ON tv_episodes (status,episode, airdate) ' )
self . connection . action ( ' CREATE INDEX idx_sta_epi_sta_air ON tv_episodes (season,episode, status, airdate) ' )
2014-04-22 23:09:29 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' UPDATE tv_episodes SET indexer = 1 ' )
2014-04-22 18:32:45 +00:00
2014-03-11 19:52:00 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-11 19:52:00 +00:00
2014-03-25 05:57:24 +00:00
2014-12-09 12:30:00 +00:00
# 23 -> 24
class ConvertIMDBInfoToIndexerScheme ( db . SchemaUpgrade ) :
2014-03-11 18:23:20 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-11 18:23:20 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Converting IMDB Info table to Indexer Scheme... ' )
2014-04-22 17:56:19 +00:00
2014-12-13 05:04:21 +00:00
if self . hasTable ( ' tmp_imdb_info ' ) :
logger . log ( u ' Removing temp imdb info tables left behind from previous updates... ' )
self . connection . action ( ' DROP TABLE tmp_imdb_info ' )
2014-04-22 17:56:19 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' ALTER TABLE imdb_info RENAME TO tmp_imdb_info ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' CREATE TABLE imdb_info (indexer_id INTEGER PRIMARY KEY, imdb_id TEXT, title TEXT, year NUMERIC, akas TEXT, runtimes NUMERIC, genres TEXT, countries TEXT, country_codes TEXT, certificates TEXT, rating TEXT, votes INTEGER, last_update NUMERIC) ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' INSERT INTO imdb_info(indexer_id, imdb_id, title, year, akas, runtimes, genres, countries, country_codes, certificates, rating, votes, last_update) SELECT tvdb_id, imdb_id, title, year, akas, runtimes, genres, countries, country_codes, certificates, rating, votes, last_update FROM tmp_imdb_info ' )
self . connection . action ( ' DROP TABLE tmp_imdb_info ' )
2014-03-11 18:23:20 +00:00
2014-03-11 19:52:00 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-11 19:52:00 +00:00
2014-03-25 05:57:24 +00:00
2014-12-09 12:30:00 +00:00
# 24 -> 25
class ConvertInfoToIndexerScheme ( db . SchemaUpgrade ) :
2014-03-11 18:23:20 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-11 18:23:20 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Converting Info table to Indexer Scheme... ' )
2014-04-22 17:56:19 +00:00
2014-12-13 05:04:21 +00:00
if self . hasTable ( ' tmp_info ' ) :
logger . log ( u ' Removing temp info tables left behind from previous updates... ' )
self . connection . action ( ' DROP TABLE tmp_info ' )
2014-04-22 17:56:19 +00:00
2014-12-13 05:04:21 +00:00
self . connection . action ( ' ALTER TABLE info RENAME TO tmp_info ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' CREATE TABLE info (last_backlog NUMERIC, last_indexer NUMERIC, last_proper_search NUMERIC) ' )
2014-03-25 05:57:24 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' INSERT INTO info(last_backlog, last_indexer, last_proper_search) SELECT last_backlog, last_tvdb, last_proper_search FROM tmp_info ' )
self . connection . action ( ' DROP TABLE tmp_info ' )
2014-03-11 19:52:00 +00:00
2014-03-18 13:50:13 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-18 13:50:13 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 25 -> 26
class AddArchiveFirstMatchOption ( db . SchemaUpgrade ) :
2014-03-18 13:50:13 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-18 13:50:13 +00:00
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' archive_firstmatch ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding column archive_firstmatch to tv_shows ' )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' archive_firstmatch ' , ' NUMERIC ' , ' 0 ' )
2014-03-18 13:50:13 +00:00
2014-03-20 05:33:34 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-20 05:33:34 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 26 -> 27
class AddSceneNumbering ( db . SchemaUpgrade ) :
2014-03-20 05:33:34 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-20 05:33:34 +00:00
2014-12-13 05:04:21 +00:00
if self . hasTable ( ' scene_numbering ' ) :
self . connection . action ( ' DROP TABLE scene_numbering ' )
2014-03-20 05:33:34 +00:00
2015-03-27 19:25:34 +00:00
logger . log ( u ' Upgrading table scene_numbering ... ' , logger . MESSAGE )
2014-03-25 05:57:24 +00:00
self . connection . action (
2015-03-27 19:25:34 +00:00
' CREATE TABLE scene_numbering (indexer TEXT, indexer_id INTEGER, season INTEGER, episode INTEGER, scene_season INTEGER, scene_episode INTEGER, PRIMARY KEY (indexer_id,season,episode)) ' )
2014-03-20 05:33:34 +00:00
2014-03-25 06:42:39 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-03-25 06:42:39 +00:00
2014-12-09 12:30:00 +00:00
# 27 -> 28
class ConvertIndexerToInteger ( db . SchemaUpgrade ) :
2014-03-25 06:42:39 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-03-25 06:42:39 +00:00
2014-07-15 02:00:53 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
logger . log ( u ' Converting Indexer to Integer ... ' , logger . MESSAGE )
cl . append ( [ ' UPDATE tv_shows SET indexer = ? WHERE LOWER(indexer) = ? ' , [ ' 1 ' , ' tvdb ' ] ] )
cl . append ( [ ' UPDATE tv_shows SET indexer = ? WHERE LOWER(indexer) = ? ' , [ ' 2 ' , ' tvrage ' ] ] )
cl . append ( [ ' UPDATE tv_episodes SET indexer = ? WHERE LOWER(indexer) = ? ' , [ ' 1 ' , ' tvdb ' ] ] )
cl . append ( [ ' UPDATE tv_episodes SET indexer = ? WHERE LOWER(indexer) = ? ' , [ ' 2 ' , ' tvrage ' ] ] )
cl . append ( [ ' UPDATE scene_numbering SET indexer = ? WHERE LOWER(indexer) = ? ' , [ ' 1 ' , ' tvdb ' ] ] )
cl . append ( [ ' UPDATE scene_numbering SET indexer = ? WHERE LOWER(indexer) = ? ' , [ ' 2 ' , ' tvrage ' ] ] )
2014-03-25 07:05:23 +00:00
2014-07-15 02:00:53 +00:00
self . connection . mass_action ( cl )
2014-03-25 06:42:39 +00:00
2014-04-24 05:18:16 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-04-24 05:18:16 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 28 -> 29
class AddRequireAndIgnoreWords ( db . SchemaUpgrade ) :
2014-12-13 05:04:21 +00:00
# Adding column rls_require_words and rls_ignore_words to tv_shows
2014-04-24 05:18:16 +00:00
def execute ( self ) :
2015-03-27 19:25:34 +00:00
if self . hasColumn ( ' tv_shows ' , ' rls_require_words ' ) and self . hasColumn ( ' tv_shows ' , ' rls_ignore_words ' ) :
self . incDBVersion ( )
return self . checkDBVersion ( )
2016-12-09 15:41:49 +00:00
db_backed_up = False
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' rls_require_words ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding column rls_require_words to tv_shows ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
db_backed_up = True
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' rls_require_words ' , ' TEXT ' , ' ' )
2014-04-24 05:18:16 +00:00
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' rls_ignore_words ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding column rls_ignore_words to tv_shows ' )
2016-12-09 15:41:49 +00:00
if not db_backed_up :
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' rls_ignore_words ' , ' TEXT ' , ' ' )
2014-04-24 05:18:16 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-04-28 09:15:29 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 29 -> 30
class AddSportsOption ( db . SchemaUpgrade ) :
2014-04-28 09:15:29 +00:00
def execute ( self ) :
2016-12-09 15:41:49 +00:00
db_backed_up = False
2014-12-13 05:04:21 +00:00
if not self . hasColumn ( ' tv_shows ' , ' sports ' ) :
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding column sports to tv_shows ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
db_backed_up = True
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_shows ' , ' sports ' , ' NUMERIC ' , ' 0 ' )
2014-04-28 09:15:29 +00:00
2014-12-13 05:04:21 +00:00
if self . hasColumn ( ' tv_shows ' , ' air_by_date ' ) and self . hasColumn ( ' tv_shows ' , ' sports ' ) :
2014-04-28 09:15:29 +00:00
# update sports column
2014-12-13 05:04:21 +00:00
logger . log ( u ' [4/4] Updating tv_shows to reflect the correct sports value... ' , logger . MESSAGE )
2016-12-09 15:41:49 +00:00
if not db_backed_up :
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-07-15 02:00:53 +00:00
cl = [ ]
2014-12-13 05:04:21 +00:00
history_quality = self . connection . select (
' SELECT * FROM tv_shows WHERE LOWER(classification) = " sports " AND air_by_date = 1 AND sports = 0 ' )
for cur_entry in history_quality :
cl . append ( [ ' UPDATE tv_shows SET sports = ? WHERE show_id = ? ' ,
[ cur_entry [ ' air_by_date ' ] , cur_entry [ ' show_id ' ] ] ] )
cl . append ( [ ' UPDATE tv_shows SET air_by_date = 0 WHERE show_id = ? ' , [ cur_entry [ ' show_id ' ] ] ] )
2014-07-15 02:00:53 +00:00
self . connection . mass_action ( cl )
2014-04-28 09:15:29 +00:00
2014-05-03 09:23:26 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-03 09:23:26 +00:00
2014-05-20 19:02:10 +00:00
2014-12-09 12:30:00 +00:00
# 30 -> 31
class AddSceneNumberingToTvEpisodes ( db . SchemaUpgrade ) :
2014-05-03 09:23:26 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-03 09:23:26 +00:00
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding columns scene_season and scene_episode to tvepisodes ' )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_episodes ' , ' scene_season ' , ' NUMERIC ' , ' NULL ' )
self . addColumn ( ' tv_episodes ' , ' scene_episode ' , ' NUMERIC ' , ' NULL ' )
2014-05-26 06:29:22 +00:00
self . incDBVersion ( )
2015-03-27 19:25:34 +00:00
return self . checkDBVersion ( )
2014-05-26 06:29:22 +00:00
2014-12-09 12:30:00 +00:00
# 31 -> 32
class AddAnimeTVShow ( db . SchemaUpgrade ) :
2014-05-26 06:29:22 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-26 06:29:22 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding column anime to tv_episodes ' )
self . addColumn ( ' tv_shows ' , ' anime ' , ' NUMERIC ' , ' 0 ' )
2014-05-26 06:29:22 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-26 06:29:22 +00:00
2014-12-09 12:30:00 +00:00
# 32 -> 33
class AddAbsoluteNumbering ( db . SchemaUpgrade ) :
2014-05-26 06:29:22 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-03 09:23:26 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding column absolute_number to tv_episodes ' )
self . addColumn ( ' tv_episodes ' , ' absolute_number ' , ' NUMERIC ' , ' 0 ' )
2014-05-03 09:23:26 +00:00
2014-05-26 06:29:22 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-26 06:29:22 +00:00
2014-12-09 12:30:00 +00:00
# 33 -> 34
class AddSceneAbsoluteNumbering ( db . SchemaUpgrade ) :
2014-05-26 06:29:22 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-26 06:29:22 +00:00
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding columns absolute_number and scene_absolute_number to scene_numbering ' )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' scene_numbering ' , ' absolute_number ' , ' NUMERIC ' , ' 0 ' )
self . addColumn ( ' scene_numbering ' , ' scene_absolute_number ' , ' NUMERIC ' , ' 0 ' )
2014-05-26 06:29:22 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-27 07:44:23 +00:00
2014-12-09 12:30:00 +00:00
# 34 -> 35
class AddAnimeBlacklistWhitelist ( db . SchemaUpgrade ) :
2014-05-27 07:44:23 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-27 07:44:23 +00:00
2016-12-09 15:41:49 +00:00
cl = [ [ ' CREATE TABLE blacklist (show_id INTEGER, range TEXT, keyword TEXT) ' ] ,
[ ' CREATE TABLE whitelist (show_id INTEGER, range TEXT, keyword TEXT) ' ] ]
2015-03-27 19:25:34 +00:00
logger . log ( u ' Creating table blacklist whitelist ' )
2014-07-15 02:00:53 +00:00
self . connection . mass_action ( cl )
2014-05-27 07:44:23 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-27 07:44:23 +00:00
2014-12-09 12:30:00 +00:00
# 35 -> 36
class AddSceneAbsoluteNumbering2 ( db . SchemaUpgrade ) :
2014-05-27 07:44:23 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-27 07:44:23 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding column scene_absolute_number to tv_episodes ' )
self . addColumn ( ' tv_episodes ' , ' scene_absolute_number ' , ' NUMERIC ' , ' 0 ' )
2014-05-27 07:44:23 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-28 21:13:29 +00:00
2014-12-09 12:30:00 +00:00
# 36 -> 37
class AddXemRefresh ( db . SchemaUpgrade ) :
2014-05-28 21:13:29 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-28 21:13:29 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Creating table xem_refresh ' )
2014-05-28 21:13:29 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' CREATE TABLE xem_refresh (indexer TEXT, indexer_id INTEGER PRIMARY KEY, last_refreshed INTEGER) ' )
2014-05-28 21:13:29 +00:00
2014-05-30 05:48:02 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-30 05:48:02 +00:00
2014-12-09 12:30:00 +00:00
# 37 -> 38
class AddSceneToTvShows ( db . SchemaUpgrade ) :
2014-05-30 05:48:02 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-05-30 05:48:02 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding column scene to tv_shows ' )
self . addColumn ( ' tv_shows ' , ' scene ' , ' NUMERIC ' , ' 0 ' )
2014-05-30 05:48:02 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-05-30 05:48:02 +00:00
2014-07-24 04:44:11 +00:00
2014-12-09 12:30:00 +00:00
# 38 -> 39
class AddIndexerMapping ( db . SchemaUpgrade ) :
2014-07-24 04:44:11 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-07-24 04:44:11 +00:00
2014-12-13 05:04:21 +00:00
if self . hasTable ( ' indexer_mapping ' ) :
self . connection . action ( ' DROP TABLE indexer_mapping ' )
2014-07-24 04:44:11 +00:00
2014-12-13 05:04:21 +00:00
logger . log ( u ' Adding table indexer_mapping ' )
2014-07-24 04:44:11 +00:00
self . connection . action (
2014-12-13 05:04:21 +00:00
' CREATE TABLE indexer_mapping (indexer_id INTEGER, indexer NUMERIC, mindexer_id INTEGER, mindexer NUMERIC, PRIMARY KEY (indexer_id, indexer)) ' )
2014-07-24 04:44:11 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
2014-07-22 04:53:32 +00:00
2014-12-09 12:30:00 +00:00
# 39 -> 40
class AddVersionToTvEpisodes ( db . SchemaUpgrade ) :
2014-07-22 04:53:32 +00:00
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-07-22 04:53:32 +00:00
2015-03-27 19:25:34 +00:00
logger . log ( u ' Adding columns release_group and version to tv_episodes ' )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' tv_episodes ' , ' release_group ' , ' TEXT ' , ' ' )
2015-03-27 19:25:34 +00:00
self . addColumn ( ' tv_episodes ' , ' version ' , ' NUMERIC ' , ' -1 ' )
logger . log ( u ' Adding column version to history ' )
2014-12-13 05:04:21 +00:00
self . addColumn ( ' history ' , ' version ' , ' NUMERIC ' , ' -1 ' )
2014-07-22 04:53:32 +00:00
self . incDBVersion ( )
2014-12-09 12:30:00 +00:00
return self . checkDBVersion ( )
# 40 -> 10000
class BumpDatabaseVersion ( db . SchemaUpgrade ) :
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2015-03-27 19:25:34 +00:00
2014-12-09 12:30:00 +00:00
logger . log ( u ' Bumping database version ' )
self . setDBVersion ( 10000 )
return self . checkDBVersion ( )
2014-12-13 05:04:21 +00:00
2015-06-05 09:44:43 +00:00
# 41,42 -> 10001
2014-12-09 12:30:00 +00:00
class Migrate41 ( db . SchemaUpgrade ) :
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-09 12:30:00 +00:00
logger . log ( u ' Bumping database version ' )
self . setDBVersion ( 10001 )
return self . checkDBVersion ( )
2016-10-01 19:31:35 +00:00
# 43,44 -> 10001
class Migrate43 ( db . SchemaUpgrade ) :
def execute ( self ) :
2016-12-09 15:41:49 +00:00
db_backed_up = False
2016-10-01 19:31:35 +00:00
db_chg = None
table = ' tmdb_info '
if self . hasTable ( table ) :
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
db_backed_up = True
2016-10-01 19:31:35 +00:00
logger . log ( u ' Dropping redundant table tmdb_info ' )
self . connection . action ( ' DROP TABLE [ %s ] ' % table )
db_chg = True
if self . hasColumn ( ' tv_shows ' , ' tmdb_id ' ) :
2016-12-09 15:41:49 +00:00
if not db_backed_up :
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
db_backed_up = True
2016-10-01 19:31:35 +00:00
logger . log ( u ' Dropping redundant tmdb_info refs ' )
self . dropColumn ( ' tv_shows ' , ' tmdb_id ' )
db_chg = True
if not self . hasTable ( ' db_version ' ) :
2016-12-09 15:41:49 +00:00
if not db_backed_up :
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2016-10-01 19:31:35 +00:00
self . connection . action ( ' PRAGMA user_version = 0 ' )
self . connection . action ( ' CREATE TABLE db_version (db_version INTEGER); ' )
self . connection . action ( ' INSERT INTO db_version (db_version) VALUES (0); ' )
if not db_chg :
logger . log ( u ' Bumping database version ' )
self . setDBVersion ( 10001 )
return self . checkDBVersion ( )
2016-06-20 01:46:10 +00:00
# 4301 -> 10002
2016-03-15 16:34:58 +00:00
class Migrate4301 ( db . SchemaUpgrade ) :
def execute ( self ) :
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2016-06-20 01:46:10 +00:00
logger . log ( u ' Bumping database version ' )
2016-03-15 16:34:58 +00:00
2016-06-20 01:46:10 +00:00
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 )
2016-03-15 16:34:58 +00:00
return self . checkDBVersion ( )
2015-03-27 19:25:34 +00:00
# 5816 - 5818 -> 15
class MigrateUpstream ( db . SchemaUpgrade ) :
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2015-03-27 19:25:34 +00:00
logger . log ( u ' Migrate SickBeard DB v %s into v15 ' % str ( self . checkDBVersion ( ) ) . replace ( ' 58 ' , ' ' ) )
self . setDBVersion ( 15 )
return self . checkDBVersion ( )
2014-12-09 12:30:00 +00:00
# 10000 -> 20000
class SickGearDatabaseVersion ( db . SchemaUpgrade ) :
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-09 12:30:00 +00:00
2015-03-27 19:25:34 +00:00
logger . log ( u ' Bumping database version to new SickGear standards ' )
2014-12-09 12:30:00 +00:00
self . setDBVersion ( 20000 )
return self . checkDBVersion ( )
2015-03-27 19:25:34 +00:00
# 10001 -> 10000
class RemoveDefaultEpStatusFromTvShows ( db . SchemaUpgrade ) :
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2015-03-27 19:25:34 +00:00
2016-06-20 01:46:10 +00:00
logger . log ( u ' Dropping redundant column default_ep_status from tv_shows ' )
2015-03-27 19:25:34 +00:00
self . dropColumn ( ' tv_shows ' , ' default_ep_status ' )
self . setDBVersion ( 10000 )
return self . checkDBVersion ( )
2016-06-20 01:46:10 +00:00
# 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 ) :
if self . hasColumn ( ' tv_shows ' , ' sub_use_sr_metadata ' ) :
logger . log ( u ' Dropping redundant column metadata sub ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2016-06-20 01:46:10 +00:00
self . dropColumn ( ' tv_shows ' , ' sub_use_sr_metadata ' )
self . setDBVersion ( 10002 )
return self . checkDBVersion ( )
2014-12-23 22:28:06 +00:00
# 20000 -> 20001
class DBIncreaseTo20001 ( db . SchemaUpgrade ) :
def execute ( self ) :
2015-03-29 15:46:46 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2014-12-23 22:28:06 +00:00
2015-03-27 19:25:34 +00:00
logger . log ( u ' Bumping database version to force a backup before new database code ' )
self . connection . action ( ' VACUUM ' )
logger . log ( u ' Performed a vacuum on the database ' , logger . DEBUG )
2014-12-23 22:28:06 +00:00
self . setDBVersion ( 20001 )
return self . checkDBVersion ( )
2014-12-13 05:04:21 +00:00
2015-03-27 19:25:34 +00:00
# 20001 -> 20002
2015-03-22 11:52:56 +00:00
class AddTvShowOverview ( db . SchemaUpgrade ) :
def execute ( self ) :
2016-03-17 19:09:07 +00:00
if not self . hasColumn ( ' tv_shows ' , ' overview ' ) :
logger . log ( u ' Adding column overview to tv_shows ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2016-03-17 19:09:07 +00:00
self . addColumn ( ' tv_shows ' , ' overview ' , ' TEXT ' , ' ' )
2015-03-22 11:52:56 +00:00
self . setDBVersion ( 20002 )
return self . checkDBVersion ( )
2015-06-05 09:44:43 +00:00
2015-04-07 03:10:50 +00:00
# 20002 -> 20003
class AddTvShowTags ( db . SchemaUpgrade ) :
def execute ( self ) :
2016-03-17 19:09:07 +00:00
if not self . hasColumn ( ' tv_shows ' , ' tag ' ) :
2016-06-20 01:46:10 +00:00
logger . log ( u ' Adding tag to tv_shows ' )
2016-12-09 15:41:49 +00:00
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
2016-03-17 19:09:07 +00:00
self . addColumn ( ' tv_shows ' , ' tag ' , ' TEXT ' , ' Show List ' )
2015-04-07 03:10:50 +00:00
self . setDBVersion ( 20003 )
2016-03-15 16:34:58 +00:00
return self . checkDBVersion ( )
2016-09-04 20:00:44 +00:00
2016-12-09 15:41:49 +00:00
2016-09-04 20:00:44 +00:00
# 20003 -> 20004
class ChangeMapIndexer ( db . SchemaUpgrade ) :
def execute ( self ) :
db . backup_database ( ' sickbeard.db ' , self . checkDBVersion ( ) )
if self . hasTable ( ' indexer_mapping ' ) :
self . connection . action ( ' DROP TABLE indexer_mapping ' )
logger . log ( u ' Changing table indexer_mapping ' )
self . connection . action (
' CREATE TABLE indexer_mapping (indexer_id INTEGER, indexer NUMERIC, mindexer_id INTEGER NOT NULL, mindexer NUMERIC, date NUMERIC NOT NULL DEFAULT 0, status INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (indexer_id, indexer, mindexer)) ' )
self . connection . action ( ' CREATE INDEX IF NOT EXISTS idx_mapping ON indexer_mapping (indexer_id, indexer) ' )
if not self . hasColumn ( ' info ' , ' last_run_backlog ' ) :
logger . log ( ' Adding last_run_backlog to info ' )
self . addColumn ( ' info ' , ' last_run_backlog ' , ' NUMERIC ' , 1 )
logger . log ( u ' Moving table scene_exceptions from cache.db to sickbeard.db ' )
if self . hasTable ( ' scene_exceptions_refresh ' ) :
self . connection . action ( ' DROP TABLE scene_exceptions_refresh ' )
self . connection . action ( ' CREATE TABLE scene_exceptions_refresh (list TEXT PRIMARY KEY, last_refreshed INTEGER) ' )
if self . hasTable ( ' scene_exceptions ' ) :
self . connection . action ( ' DROP TABLE scene_exceptions ' )
self . connection . action ( ' CREATE TABLE scene_exceptions (exception_id INTEGER PRIMARY KEY, indexer_id INTEGER KEY, show_name TEXT, season NUMERIC, custom NUMERIC) ' )
try :
cachedb = db . DBConnection ( filename = ' cache.db ' )
if cachedb . hasTable ( ' scene_exceptions ' ) :
sqlResults = cachedb . action ( ' SELECT * FROM scene_exceptions ' )
cs = [ ]
for r in sqlResults :
cs . append ( [ ' INSERT OR REPLACE INTO scene_exceptions (exception_id, indexer_id, show_name, season, custom) '
' VALUES (?,?,?,?,?) ' , [ r [ ' exception_id ' ] , r [ ' indexer_id ' ] , r [ ' show_name ' ] ,
r [ ' season ' ] , r [ ' custom ' ] ] ] )
if len ( cs ) > 0 :
self . connection . mass_action ( cs )
except :
pass
keep_tables = { ' scene_exceptions ' , ' scene_exceptions_refresh ' , ' info ' , ' indexer_mapping ' , ' blacklist ' ,
' db_version ' , ' history ' , ' imdb_info ' , ' lastUpdate ' , ' scene_numbering ' , ' tv_episodes ' , ' tv_shows ' ,
' whitelist ' , ' xem_refresh ' }
current_tables = set ( self . listTables ( ) )
remove_tables = list ( current_tables - keep_tables )
for table in remove_tables :
self . connection . action ( ' DROP TABLE [ %s ] ' % table )
self . connection . action ( ' VACUUM ' )
self . setDBVersion ( 20004 )
return self . checkDBVersion ( )