Merge pull request #834 from mcarlton00/omega-migration

Add automatic database migration for Kodi Omega
This commit is contained in:
Odd Stråbø 2024-03-20 02:44:57 +01:00 committed by GitHub
commit d1a5c98152
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 7 deletions

View file

@ -11,6 +11,7 @@ from six.moves import queue as Queue
from kodi_six import xbmc, xbmcgui
from .objects import Movies, TVShows, MusicVideos, Music
from .objects.kodi import Movies as KodiDb
from .database import Database, jellyfin_db, get_sync, save_sync
from .full_sync import FullSync
from .views import Views
@ -122,6 +123,14 @@ class Library(threading.Thread):
# Make sure we always have a version in the database
db.add_version((TARGET_DB_VERSION))
# Video Database Migrations
with Database('video') as videodb:
vid_db = KodiDb(videodb.cursor)
if vid_db.migrations():
LOG.info('changes detected, reloading skin')
xbmc.executebuiltin('UpdateLibrary(video)')
xbmc.executebuiltin('ReloadSkin()')
@stop
def service(self):

View file

@ -50,7 +50,7 @@ class Movies(Kodi):
def add_videoversion(self, *args):
self.cursor.execute(QU.check_video_version)
if self.cursor.fetchone()[0]==1 :
if self.cursor.fetchone()[0] == 1:
self.cursor.execute(QU.add_video_version, args)
def update(self, *args):
@ -61,11 +61,9 @@ class Movies(Kodi):
self.cursor.execute(QU.delete_movie, (kodi_id,))
self.cursor.execute(QU.delete_file, (file_id,))
self.cursor.execute(QU.check_video_version)
if self.cursor.fetchone()[0]==1 :
if self.cursor.fetchone()[0] == 1:
self.cursor.execute(QU.delete_video_version, (file_id,))
def get_rating_id(self, *args):
try:
@ -141,3 +139,35 @@ class Movies(Kodi):
def delete_boxset(self, *args):
self.cursor.execute(QU.delete_set, args)
def migrations(self):
'''
Used to trigger required database migrations for new versions
'''
self.cursor.execute(QU.get_version)
version_id = self.cursor.fetchone()[0]
changes = False
# Will run every time Kodi starts, but will be fast enough on
# subsequent runs to not be a meaningful delay
if version_id >= 131:
changes = self.omega_migration()
return changes
def omega_migration(self):
'''
Adds a video version for all existing movies
'''
LOG.info('Starting migration for Omega database changes')
# Tracks if this migration made any changes
changes = False
self.cursor.execute(QU.get_missing_versions)
# Sets all existing movies without a version to standard version
for entry in self.cursor.fetchall():
self.add_videoversion(entry[0], entry[1], "movie", "0", 40400)
changes = True
LOG.info('Omega database migration is complete')
return changes

View file

@ -322,7 +322,7 @@ VALUES (?, ?, ?, ?, ?)
check_video_version = """
SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='videoversion'
"""
add_video_version_obj = ["{FileId}","{MovieId}","movie","0",40400]
add_video_version_obj = ["{FileId}", "{MovieId}", "movie", "0", 40400]
add_musicvideo = """
INSERT INTO musicvideo(idMVideo, idFile, c00, c04, c05, c06, c07, c08, c09, c10,
c11, c12, premiered)
@ -581,3 +581,15 @@ WHERE media_id = ?
AND media_type = ?
AND type LIKE ?
"""
get_missing_versions = """
SELECT idFile,idMovie
FROM movie
WHERE NOT EXISTS (
SELECT NULL FROM videoversion
WHERE videoversion.idMedia = movie.idMovie
)
"""
get_version = """
SELECT idVersion
FROM version
"""