2018-07-13 02:46:02 +10:00
|
|
|
#!/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')
|
2019-09-11 01:56:56 +10: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-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
|
|
|
|
|
2021-01-25 03:02:47 +11:00
|
|
|
if not utils.compare_version(last_migration, '3.0.4'):
|
2021-01-12 02:21:37 +11:00
|
|
|
LOG.info('Migrating to version 3.0.4')
|
|
|
|
# Add an additional column `trailer_synced` in the Plex movie table
|
2019-06-28 23:27:02 +10:00
|
|
|
from .plex_db import PlexDB
|
|
|
|
with PlexDB() as plexdb:
|
2021-01-12 02:21:37 +11:00
|
|
|
query = 'ALTER TABLE movie ADD trailer_synced BOOLEAN'
|
|
|
|
plexdb.cursor.execute(query)
|
2019-06-28 23:27:02 +10:00
|
|
|
# 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)
|