mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Add automatic database migration for Kodi Omega
This commit is contained in:
parent
6ca919c0d7
commit
373d34a56e
3 changed files with 58 additions and 7 deletions
|
@ -11,6 +11,7 @@ from six.moves import queue as Queue
|
||||||
from kodi_six import xbmc, xbmcgui
|
from kodi_six import xbmc, xbmcgui
|
||||||
|
|
||||||
from .objects import Movies, TVShows, MusicVideos, Music
|
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 .database import Database, jellyfin_db, get_sync, save_sync
|
||||||
from .full_sync import FullSync
|
from .full_sync import FullSync
|
||||||
from .views import Views
|
from .views import Views
|
||||||
|
@ -122,6 +123,14 @@ class Library(threading.Thread):
|
||||||
# Make sure we always have a version in the database
|
# Make sure we always have a version in the database
|
||||||
db.add_version((TARGET_DB_VERSION))
|
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
|
@stop
|
||||||
def service(self):
|
def service(self):
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Movies(Kodi):
|
||||||
|
|
||||||
def add_videoversion(self, *args):
|
def add_videoversion(self, *args):
|
||||||
self.cursor.execute(QU.check_video_version)
|
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)
|
self.cursor.execute(QU.add_video_version, args)
|
||||||
|
|
||||||
def update(self, *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_movie, (kodi_id,))
|
||||||
self.cursor.execute(QU.delete_file, (file_id,))
|
self.cursor.execute(QU.delete_file, (file_id,))
|
||||||
self.cursor.execute(QU.check_video_version)
|
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,))
|
self.cursor.execute(QU.delete_video_version, (file_id,))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_rating_id(self, *args):
|
def get_rating_id(self, *args):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -141,3 +139,35 @@ class Movies(Kodi):
|
||||||
|
|
||||||
def delete_boxset(self, *args):
|
def delete_boxset(self, *args):
|
||||||
self.cursor.execute(QU.delete_set, 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
|
||||||
|
|
|
@ -322,7 +322,7 @@ VALUES (?, ?, ?, ?, ?)
|
||||||
check_video_version = """
|
check_video_version = """
|
||||||
SELECT COUNT(name) FROM sqlite_master WHERE type='table' AND name='videoversion'
|
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 = """
|
add_musicvideo = """
|
||||||
INSERT INTO musicvideo(idMVideo, idFile, c00, c04, c05, c06, c07, c08, c09, c10,
|
INSERT INTO musicvideo(idMVideo, idFile, c00, c04, c05, c06, c07, c08, c09, c10,
|
||||||
c11, c12, premiered)
|
c11, c12, premiered)
|
||||||
|
@ -581,3 +581,15 @@ WHERE media_id = ?
|
||||||
AND media_type = ?
|
AND media_type = ?
|
||||||
AND type LIKE ?
|
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
|
||||||
|
"""
|
||||||
|
|
Loading…
Reference in a new issue