mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Merge pull request #834 from mcarlton00/omega-migration
Add automatic database migration for Kodi Omega
This commit is contained in:
commit
d1a5c98152
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):
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,6 @@ class Movies(Kodi):
|
||||||
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
|
||||||
|
|
|
@ -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