Add update_state table to persist pts and such

This commit is contained in:
Lonami Exo 2018-04-23 21:16:09 +02:00
parent e616af8a70
commit ea404c5477

View File

@ -13,7 +13,7 @@ from ..tl.types import (
) )
EXTENSION = '.session' EXTENSION = '.session'
CURRENT_VERSION = 3 # database version CURRENT_VERSION = 4 # database version
class SQLiteSession(MemorySession): class SQLiteSession(MemorySession):
@ -99,6 +99,14 @@ class SQLiteSession(MemorySession):
hash integer, hash integer,
primary key(md5_digest, file_size, type) primary key(md5_digest, file_size, type)
)""" )"""
,
"""update_state (
id integer primary key,
pts integer,
qts integer,
date integer,
seq integer
)"""
) )
c.execute("insert into version values (?)", (CURRENT_VERSION,)) c.execute("insert into version values (?)", (CURRENT_VERSION,))
# Migrating from JSON -> new table and may have entities # Migrating from JSON -> new table and may have entities
@ -141,18 +149,30 @@ class SQLiteSession(MemorySession):
def _upgrade_database(self, old): def _upgrade_database(self, old):
c = self._cursor() c = self._cursor()
# old == 1 doesn't have the old sent_files so no need to drop if old == 1:
old += 1
# old == 1 doesn't have the old sent_files so no need to drop
if old == 2: if old == 2:
old += 1
# Old cache from old sent_files lasts then a day anyway, drop # Old cache from old sent_files lasts then a day anyway, drop
c.execute('drop table sent_files') c.execute('drop table sent_files')
self._create_table(c, """sent_files ( self._create_table(c, """sent_files (
md5_digest blob, md5_digest blob,
file_size integer, file_size integer,
type integer, type integer,
id integer, id integer,
hash integer, hash integer,
primary key(md5_digest, file_size, type) primary key(md5_digest, file_size, type)
)""") )""")
if old == 3:
old += 1
self._create_table(c, """update_state (
id integer primary key,
pts integer,
qts integer,
date integer,
seq integer
)""")
c.close() c.close()
@staticmethod @staticmethod