Merge pull request #528 from mcarlton00/database-version

Store a version parameter in the database for migrations
This commit is contained in:
Odd Stråbø 2021-05-28 15:15:07 +02:00 committed by GitHub
commit 65c7a5c59c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -144,3 +144,15 @@ class JellyfinDatabase():
def remove_media_by_parent_id(self, *args):
self.cursor.execute(QU.delete_media_by_parent_id, args)
def get_version(self):
self.cursor.execute(QU.get_version)
return self.cursor.fetchone()
def add_version(self, *args):
'''
We only ever want one value here, so erase the existing contents first
'''
self.cursor.execute(QU.delete_version)
self.cursor.execute(QU.add_version, args)

View file

@ -26,6 +26,7 @@ from helper import LazyLogger
LOG = LazyLogger(__name__)
LIMIT = int(settings('limitIndex') or 15)
DTHREADS = int(settings('limitThreads') or 3)
TARGET_DB_VERSION = 1
##################################################################################################
@ -110,6 +111,18 @@ class Library(threading.Thread):
with Database('video'), Database('music'):
pass
def check_version(self):
'''
Checks database version and triggers any required data migrations
'''
with Database('jellyfin') as jellyfindb:
db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor)
db_version = db.get_version()
if not db_version:
# Make sure we always have a version in the database
db.add_version((TARGET_DB_VERSION))
@stop
def service(self):
@ -303,6 +316,7 @@ class Library(threading.Thread):
Check for the server plugin.
'''
self.test_databases()
self.check_version()
Views().get_views()
Views().get_nodes()