PlexKodiConnect/resources/lib/migration.py

35 lines
1.2 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
2017-05-30 01:29:29 +10:00
from logging import getLogger
2018-06-22 03:24:37 +10:00
from . import variables as v
from . import utils
2017-05-30 01:29:29 +10:00
###############################################################################
2018-06-22 03:24:37 +10:00
LOG = getLogger('PLEX.migration')
2017-05-30 01:29:29 +10:00
def check_migration():
2018-06-22 03:24:37 +10:00
LOG.info('Checking whether we need to migrate something')
last_migration = utils.settings('last_migrated_PKC_version')
# Ensure later migration if user downgraded PKC!
utils.settings('last_migrated_PKC_version', value=v.ADDON_VERSION)
if last_migration == '':
LOG.info('New, clean PKC installation - no migration necessary')
return
elif last_migration == v.ADDON_VERSION:
2018-06-22 03:24:37 +10:00
LOG.info('Already migrated to PKC version %s' % v.ADDON_VERSION)
2017-05-30 01:29:29 +10:00
return
if not utils.compare_version(last_migration, '3.0.4'):
LOG.info('Migrating to version 3.0.4')
# Add an additional column `trailer_synced` in the Plex movie table
from .plex_db import PlexDB
with PlexDB() as plexdb:
query = 'ALTER TABLE movie ADD trailer_synced BOOLEAN'
plexdb.cursor.execute(query)
# Index will be automatically recreated on next PKC startup
2018-06-22 03:24:37 +10:00
utils.settings('last_migrated_PKC_version', value=v.ADDON_VERSION)