From b3a7850b55fe001cd3dfbafc3f83f051329424bd Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Mon, 29 Mar 2021 00:20:38 -0700 Subject: [PATCH] Add version info to database --- plexpy/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plexpy/__init__.py b/plexpy/__init__.py index 425eac86..f6b170bc 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -46,6 +46,7 @@ if PYTHON2: import database import datafactory import exporter + import helpers import libraries import logger import mobile_app @@ -67,6 +68,7 @@ else: from plexpy import database from plexpy import datafactory from plexpy import exporter + from plexpy import helpers from plexpy import libraries from plexpy import logger from plexpy import mobile_app @@ -600,6 +602,11 @@ def dbcheck(): conn_db = sqlite3.connect(DB_FILE) c_db = conn_db.cursor() + # schema table :: This is a table which keeps track of the database version + c_db.execute( + 'CREATE TABLE IF NOT EXISTS version_info (key TEXT UNIQUE, value TEXT)' + ) + # sessions table :: This is a temp table that logs currently active sessions c_db.execute( 'CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, session_key INTEGER, session_id TEXT, ' @@ -2456,6 +2463,19 @@ def dbcheck(): 'ON "sessions_continued" ("user_id", "machine_id", "media_type")' ) + # Set database version + result = c_db.execute('SELECT value FROM version_info WHERE key = "version"').fetchone() + if not result: + c_db.execute( + 'INSERT OR REPLACE INTO version_info (key, value) VALUES ("version", ?)', + [common.RELEASE] + ) + elif helpers.version_to_tuple(result[0]) < helpers.version_to_tuple(common.RELEASE): + c_db.execute( + 'UPDATE version_info SET value = ? WHERE key = "version"', + [common.RELEASE] + ) + conn_db.commit() c_db.close()