Migrate db version to emby database

This commit is contained in:
angelblue05 2016-09-15 05:31:15 -05:00
parent b43c9343ca
commit 11a068cd30
3 changed files with 39 additions and 4 deletions

View file

@ -20,6 +20,21 @@ class Embydb_Functions():
self.embycursor = embycursor
def get_version(self, version=None):
if version is not None:
query = "INSERT INTO version(idVersion) VALUES (?)"
self.embycursor.execute(query, (version,))
else:
query = "SELECT idVersion FROM version"
self.embycursor.execute(query)
try:
version = self.embycursor.fetchone()[0]
except TypeError:
pass
return version
def getViews(self):
views = []

View file

@ -311,10 +311,14 @@ class LibrarySync(threading.Thread):
if pDialog:
pDialog.close()
emby_db = embydb.Embydb_Functions(embycursor)
current_version = emby_db.get_version(self.clientInfo.get_version())
window('emby_version', current_version)
embyconn.commit()
embycursor.close()
settings('SyncInstallRunDone', value="true")
settings("dbCreatedWithVersion", self.clientInfo.get_version())
self.saveLastSync()
xbmc.executebuiltin('UpdateLibrary(video)')
elapsedtotal = datetime.now() - starttotal
@ -891,6 +895,7 @@ class LibrarySync(threading.Thread):
def compareDBVersion(self, current, minimum):
# It returns True is database is up to date. False otherwise.
log.info("current: %s minimum: %s" % (current, minimum))
currMajor, currMinor, currPatch = current.split(".")
minMajor, minMinor, minPatch = minimum.split(".")
@ -941,7 +946,20 @@ class LibrarySync(threading.Thread):
if (window('emby_dbCheck') != "true" and settings('SyncInstallRunDone') == "true"):
# Verify the validity of the database
currentVersion = settings('dbCreatedWithVersion')
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
currentVersion = emby_db.get_version()
###$ Begin migration $###
if currentVersion is None:
currentVersion = emby_db.get_version(settings('dbCreatedWithVersion'))
embyconn.commit()
log.info("Migration of database version completed")
###$ End migration $###
embycursor.close()
window('emby_version', value=currentVersion)
minVersion = window('emby_minDBVersion')
uptoDate = self.compareDBVersion(currentVersion, minVersion)
@ -977,8 +995,9 @@ class LibrarySync(threading.Thread):
line1=lang(33024))
break
# Run start up sync
log.warn("Database version: %s" % settings('dbCreatedWithVersion'))
log.warn("Database version: %s", window('emby_version'))
log.info("SyncDatabase (started)")
startTime = datetime.now()
librarySync = self.startSync()

View file

@ -392,6 +392,7 @@ def reset():
cursor.execute("DELETE FROM " + tablename)
cursor.execute('DROP table IF EXISTS emby')
cursor.execute('DROP table IF EXISTS view')
cursor.execute("DELETE FROM version")
connection.commit()
cursor.close()