Add flag for offical mobile app

This commit is contained in:
JonnyWong16 2020-06-20 16:16:35 -07:00
commit 7c801c2f5e
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
6 changed files with 38 additions and 21 deletions

View file

@ -745,7 +745,7 @@ def dbcheck():
c_db.execute(
'CREATE TABLE IF NOT EXISTS mobile_devices (id INTEGER PRIMARY KEY AUTOINCREMENT, '
'device_id TEXT NOT NULL UNIQUE, device_token TEXT, device_name TEXT, friendly_name TEXT, '
'last_seen INTEGER)'
'last_seen INTEGER, official INTEGER DEFAULT 0)'
)
# tvmaze_lookup table :: This table keeps record of the TVmaze lookups
@ -2001,6 +2001,19 @@ def dbcheck():
'ALTER TABLE mobile_devices ADD COLUMN last_seen INTEGER'
)
# Upgrade mobile_devices table from earlier versions
try:
c_db.execute('SELECT official FROM mobile_devices')
except sqlite3.OperationalError:
logger.debug("Altering database. Updating database table mobile_devices.")
c_db.execute(
'ALTER TABLE mobile_devices ADD COLUMN official INTEGER DEFAULT 0'
)
# Update official mobile device flag
for device_id, in c_db.execute('SELECT device_id FROM mobile_devices').fetchall():
c_db.execute('UPDATE mobile_devices SET official = ? WHERE device_id = ?',
[mobile_app.validate_device_id(device_id), device_id])
# Upgrade notifiers table from earlier versions
try:
c_db.execute('SELECT custom_conditions FROM notifiers')