Drop Plex tables entirely on DB reset; no further version check needed

This commit is contained in:
croneter 2018-10-25 12:55:25 +02:00
parent c2efe0d57f
commit a603fbadca
2 changed files with 1 additions and 26 deletions

View file

@ -196,29 +196,6 @@ def initialize():
Run once upon PKC startup to verify that plex db exists.
"""
with PlexDBBase() as plexdb:
init = False
# Create the tables for the plex database
try:
plexdb.cursor.execute('SELECT * FROM version')
version = plexdb.cursor.fetchone()[0]
except (utils.OperationalError, TypeError):
init = True
else:
init = not utils.compare_version(version, v.MIN_PLEX_DB_VERSION)
if not init:
return
# Delete all tables
from logging import getLogger
LOG = getLogger('PLEX.plex_db')
LOG.warn('Need to reset the Plex database')
plexdb.cursor.execute('''
SELECT name FROM sqlite_master WHERE type = 'table'
''')
tables = [x[0] for x in plexdb.cursor]
for table in tables:
query = 'DROP table IF EXISTS %s' % table
plexdb.cursor.execute(query)
# Set them up again
plexdb.cursor.execute('''
CREATE TABLE IF NOT EXISTS version(
idVersion TEXT)
@ -334,5 +311,5 @@ def wipe():
tables = plexdb.cursor.fetchall()
tables = [i[0] for i in tables]
for table in tables:
delete_query = 'DELETE FROM %s' % table
delete_query = 'DROP table IF EXISTS %s' % table
plexdb.cursor.execute(delete_query)

View file

@ -85,8 +85,6 @@ PKC_MACHINE_IDENTIFIER = None
# Minimal PKC version needed for the Kodi database - otherwise need to recreate
MIN_DB_VERSION = '2.5.0'
# Minimal PKC version needed for the Plex database
MIN_PLEX_DB_VERSION = '2.5.0'
# Database paths
DB_VIDEO_VERSION = {