2018-07-12 18:46:02 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2017-05-29 17:29:29 +02:00
|
|
|
from logging import getLogger
|
2018-06-21 19:24:37 +02:00
|
|
|
|
|
|
|
from . import variables as v
|
|
|
|
from . import utils
|
2017-05-29 17:29:29 +02:00
|
|
|
###############################################################################
|
|
|
|
|
2018-06-21 19:24:37 +02:00
|
|
|
LOG = getLogger('PLEX.migration')
|
2017-05-29 17:29:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
def check_migration():
|
2018-06-21 19:24:37 +02:00
|
|
|
LOG.info('Checking whether we need to migrate something')
|
|
|
|
last_migration = utils.settings('last_migrated_PKC_version')
|
2019-09-10 17:56:56 +02:00
|
|
|
# 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-21 19:24:37 +02:00
|
|
|
LOG.info('Already migrated to PKC version %s' % v.ADDON_VERSION)
|
2017-05-29 17:29:29 +02:00
|
|
|
return
|
|
|
|
|
2021-01-24 17:02:47 +01:00
|
|
|
if not utils.compare_version(last_migration, '3.0.4'):
|
2021-01-11 16:21:37 +01:00
|
|
|
LOG.info('Migrating to version 3.0.4')
|
|
|
|
# Add an additional column `trailer_synced` in the Plex movie table
|
2019-06-28 15:27:02 +02:00
|
|
|
from .plex_db import PlexDB
|
|
|
|
with PlexDB() as plexdb:
|
2021-01-11 16:21:37 +01:00
|
|
|
query = 'ALTER TABLE movie ADD trailer_synced BOOLEAN'
|
|
|
|
plexdb.cursor.execute(query)
|
2019-06-28 15:27:02 +02:00
|
|
|
# Index will be automatically recreated on next PKC startup
|
|
|
|
|
2018-06-21 19:24:37 +02:00
|
|
|
utils.settings('last_migrated_PKC_version', value=v.ADDON_VERSION)
|