Add version info to database

This commit is contained in:
JonnyWong16 2021-03-29 00:20:38 -07:00
parent 01c4f45b77
commit b3a7850b55
No known key found for this signature in database
GPG key ID: B1F1F9807184697A

View file

@ -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()