Add DB fix and renamed Activity chart to Device presence over time

This commit is contained in:
jokob-sk
2022-07-23 18:24:48 +10:00
parent aca6363a74
commit 2e9f9f5b59
9 changed files with 37 additions and 21 deletions

View File

@@ -1480,17 +1480,31 @@ def send_email (pText, pHTML):
#===============================================================================
# DB
#===============================================================================
def upgradeDB ():
def upgradeDB ():
openDB()
# check if table exists
listOfTables = sql.execute(
"""SELECT name FROM sqlite_master WHERE type='table'
AND name='Online_History'; """).fetchall()
# indicates, if Online_History table is available
onlineHistoryAvailable = sql.execute("""
SELECT name FROM sqlite_master WHERE type='table'
AND name='Online_History';
""").fetchall() != []
# Check if it is incompatible (Check if table has all required columns)
isIncompatible = False
if listOfTables == []:
print_log ('Upgrading DB (creating Online_History table)')
if onlineHistoryAvailable :
isIncompatible = sql.execute ("""
SELECT COUNT(*) AS CNTREC FROM pragma_table_info('Online_History') WHERE name='Archived_Devices'
""").fetchone()[0] == 0
# Drop table if available, but incompatible
if onlineHistoryAvailable and isIncompatible:
print_log ('Table is incompatible, Dropping the Online_History table)')
sql.execute("DROP TABLE Online_History;")
onlineHistoryAvailable = False
if onlineHistoryAvailable == False :
sql.execute("""
CREATE TABLE "Online_History" (
"Index" INTEGER,
@@ -1503,6 +1517,7 @@ def upgradeDB ():
);
""")
#-------------------------------------------------------------------------------
def openDB ():