mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-08 11:03:38 +00:00
Merge pull request #1051 from JackDandy/feature/AddTestDBVersions
Add support for a testing.db version (>=100000).
This commit is contained in:
commit
e479856245
5 changed files with 49 additions and 13 deletions
51
SickBeard.py
51
SickBeard.py
|
@ -76,6 +76,7 @@ from sickbeard.exceptions import ex
|
||||||
from lib.configobj import ConfigObj
|
from lib.configobj import ConfigObj
|
||||||
|
|
||||||
throwaway = datetime.datetime.strptime('20110101', '%Y%m%d')
|
throwaway = datetime.datetime.strptime('20110101', '%Y%m%d')
|
||||||
|
rollback_loaded = None
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, sickbeard.sig_handler)
|
signal.signal(signal.SIGINT, sickbeard.sig_handler)
|
||||||
signal.signal(signal.SIGTERM, sickbeard.sig_handler)
|
signal.signal(signal.SIGTERM, sickbeard.sig_handler)
|
||||||
|
@ -153,6 +154,19 @@ class SickGear(object):
|
||||||
|
|
||||||
return '\n'.join(help_msg)
|
return '\n'.join(help_msg)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def execute_rollback(mo, max_v):
|
||||||
|
global rollback_loaded
|
||||||
|
try:
|
||||||
|
if None is rollback_loaded:
|
||||||
|
rollback_loaded = db.get_rollback_module()
|
||||||
|
if None is not rollback_loaded:
|
||||||
|
rollback_loaded.__dict__[mo]().run(max_v)
|
||||||
|
else:
|
||||||
|
print(u'ERROR: Could not download Rollback Module.')
|
||||||
|
except (StandardError, Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
# do some preliminary stuff
|
# do some preliminary stuff
|
||||||
sickbeard.MY_FULLNAME = os.path.normpath(os.path.abspath(__file__))
|
sickbeard.MY_FULLNAME = os.path.normpath(os.path.abspath(__file__))
|
||||||
|
@ -324,14 +338,28 @@ class SickGear(object):
|
||||||
print('Stack Size %s not set: %s' % (stack_size, e.message))
|
print('Stack Size %s not set: %s' % (stack_size, e.message))
|
||||||
|
|
||||||
# check all db versions
|
# check all db versions
|
||||||
for d, min_v, max_v, mo in [
|
for d, min_v, max_v, base_v, mo in [
|
||||||
('failed.db', sickbeard.failed_db.MIN_DB_VERSION, sickbeard.failed_db.MAX_DB_VERSION, 'FailedDb'),
|
('failed.db', sickbeard.failed_db.MIN_DB_VERSION, sickbeard.failed_db.MAX_DB_VERSION, sickbeard.failed_db.TEST_BASE_VERSION, 'FailedDb'),
|
||||||
('cache.db', sickbeard.cache_db.MIN_DB_VERSION, sickbeard.cache_db.MAX_DB_VERSION, 'CacheDb'),
|
('cache.db', sickbeard.cache_db.MIN_DB_VERSION, sickbeard.cache_db.MAX_DB_VERSION, sickbeard.cache_db.TEST_BASE_VERSION, 'CacheDb'),
|
||||||
('sickbeard.db', sickbeard.mainDB.MIN_DB_VERSION, sickbeard.mainDB.MAX_DB_VERSION, 'MainDb')
|
('sickbeard.db', sickbeard.mainDB.MIN_DB_VERSION, sickbeard.mainDB.MAX_DB_VERSION, sickbeard.mainDB.TEST_BASE_VERSION, 'MainDb')
|
||||||
]:
|
]:
|
||||||
cur_db_version = db.DBConnection(d).checkDBVersion()
|
cur_db_version = db.DBConnection(d).checkDBVersion()
|
||||||
|
|
||||||
if cur_db_version > 0:
|
# handling of standalone TEST db versions
|
||||||
|
if cur_db_version >= 100000 and cur_db_version != max_v:
|
||||||
|
print('Your [%s] database version (%s) is a test db version and doesn\'t match SickGear required '
|
||||||
|
'version (%s), downgrading to production db' % (d, cur_db_version, max_v))
|
||||||
|
self.execute_rollback(mo, max_v)
|
||||||
|
cur_db_version = db.DBConnection(d).checkDBVersion()
|
||||||
|
if cur_db_version >= 100000:
|
||||||
|
print(u'Rollback to production failed.')
|
||||||
|
sys.exit(u'If you have used other forks, your database may be unusable due to their changes')
|
||||||
|
if 100000 <= max_v and None is not base_v:
|
||||||
|
max_v = base_v # set max_v to the needed base production db for test_db
|
||||||
|
print(u'Rollback to production of [%s] successful.' % d)
|
||||||
|
|
||||||
|
# handling of production db versions
|
||||||
|
if 0 < cur_db_version < 100000:
|
||||||
if cur_db_version < min_v:
|
if cur_db_version < min_v:
|
||||||
print(u'Your [%s] database version (%s) is too old to migrate from with this version of SickGear'
|
print(u'Your [%s] database version (%s) is too old to migrate from with this version of SickGear'
|
||||||
% (d, cur_db_version))
|
% (d, cur_db_version))
|
||||||
|
@ -341,19 +369,16 @@ class SickGear(object):
|
||||||
print(u'Your [%s] database version (%s) has been incremented past'
|
print(u'Your [%s] database version (%s) has been incremented past'
|
||||||
u' what this version of SickGear supports. Trying to rollback now. Please wait...' %
|
u' what this version of SickGear supports. Trying to rollback now. Please wait...' %
|
||||||
(d, cur_db_version))
|
(d, cur_db_version))
|
||||||
try:
|
self.execute_rollback(mo, max_v)
|
||||||
rollback_loaded = db.get_rollback_module()
|
|
||||||
if None is not rollback_loaded:
|
|
||||||
rollback_loaded.__dict__[mo]().run(max_v)
|
|
||||||
else:
|
|
||||||
print(u'ERROR: Could not download Rollback Module.')
|
|
||||||
except (StandardError, Exception):
|
|
||||||
pass
|
|
||||||
if db.DBConnection(d).checkDBVersion() > max_v:
|
if db.DBConnection(d).checkDBVersion() > max_v:
|
||||||
print(u'Rollback failed.')
|
print(u'Rollback failed.')
|
||||||
sys.exit(u'If you have used other forks, your database may be unusable due to their changes')
|
sys.exit(u'If you have used other forks, your database may be unusable due to their changes')
|
||||||
print(u'Rollback of [%s] successful.' % d)
|
print(u'Rollback of [%s] successful.' % d)
|
||||||
|
|
||||||
|
# free memory
|
||||||
|
global rollback_loaded
|
||||||
|
rollback_loaded = None
|
||||||
|
|
||||||
# Initialize the config and our threads
|
# Initialize the config and our threads
|
||||||
sickbeard.initialize(console_logging=self.console_logging)
|
sickbeard.initialize(console_logging=self.console_logging)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import re
|
||||||
|
|
||||||
MIN_DB_VERSION = 1
|
MIN_DB_VERSION = 1
|
||||||
MAX_DB_VERSION = 4
|
MAX_DB_VERSION = 4
|
||||||
|
TEST_BASE_VERSION = None # the base production db version, only needed for TEST db versions (>=100000)
|
||||||
|
|
||||||
|
|
||||||
# Add new migrations at the bottom of the list; subclass the previous migration.
|
# Add new migrations at the bottom of the list; subclass the previous migration.
|
||||||
|
|
|
@ -21,6 +21,7 @@ from sickbeard.common import Quality
|
||||||
|
|
||||||
MIN_DB_VERSION = 1
|
MIN_DB_VERSION = 1
|
||||||
MAX_DB_VERSION = 1
|
MAX_DB_VERSION = 1
|
||||||
|
TEST_BASE_VERSION = None # the base production db version, only needed for TEST db versions (>=100000)
|
||||||
|
|
||||||
# Add new migrations at the bottom of the list; subclass the previous migration.
|
# Add new migrations at the bottom of the list; subclass the previous migration.
|
||||||
class InitialSchema(db.SchemaUpgrade):
|
class InitialSchema(db.SchemaUpgrade):
|
||||||
|
|
|
@ -28,6 +28,7 @@ from sickbeard.name_parser.parser import NameParser, InvalidNameException, Inval
|
||||||
|
|
||||||
MIN_DB_VERSION = 9 # oldest db version we support migrating from
|
MIN_DB_VERSION = 9 # oldest db version we support migrating from
|
||||||
MAX_DB_VERSION = 20008
|
MAX_DB_VERSION = 20008
|
||||||
|
TEST_BASE_VERSION = None # the base production db version, only needed for TEST db versions (>=100000)
|
||||||
|
|
||||||
|
|
||||||
class MainSanityCheck(db.DBSanityCheck):
|
class MainSanityCheck(db.DBSanityCheck):
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import unittest
|
import unittest
|
||||||
import test_lib as test
|
import test_lib as test
|
||||||
|
from sickbeard import cache_db, mainDB, failed_db
|
||||||
|
|
||||||
|
|
||||||
class DBBasicTests(test.SickbeardTestDBCase):
|
class DBBasicTests(test.SickbeardTestDBCase):
|
||||||
|
@ -28,9 +29,16 @@ class DBBasicTests(test.SickbeardTestDBCase):
|
||||||
super(DBBasicTests, self).setUp()
|
super(DBBasicTests, self).setUp()
|
||||||
self.db = test.db.DBConnection()
|
self.db = test.db.DBConnection()
|
||||||
|
|
||||||
|
def is_testdb(self, version):
|
||||||
|
if isinstance(version, (int, long)):
|
||||||
|
return 100000 <= version
|
||||||
|
|
||||||
def test_select(self):
|
def test_select(self):
|
||||||
self.db.select('SELECT * FROM tv_episodes WHERE showid = ? AND location != ""', [0000])
|
self.db.select('SELECT * FROM tv_episodes WHERE showid = ? AND location != ""', [0000])
|
||||||
self.db.close()
|
self.db.close()
|
||||||
|
self.assertEqual(cache_db.TEST_BASE_VERSION is not None, self.is_testdb(cache_db.MAX_DB_VERSION))
|
||||||
|
self.assertEqual(mainDB.TEST_BASE_VERSION is not None, self.is_testdb(mainDB.MAX_DB_VERSION))
|
||||||
|
self.assertEqual(failed_db.TEST_BASE_VERSION is not None, self.is_testdb(failed_db.MAX_DB_VERSION))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print('==================')
|
print('==================')
|
||||||
|
|
Loading…
Reference in a new issue