Move check version and create tables from __init__

This commit is contained in:
Alexander Lozovskoy 2023-03-25 16:32:31 +03:00
parent 516a2e7435
commit 85151428a7

View File

@ -48,6 +48,12 @@ class SQLiteSession(MemorySession):
c.execute("select name from sqlite_master " c.execute("select name from sqlite_master "
"where type='table' and name='version'") "where type='table' and name='version'")
if c.fetchone(): if c.fetchone():
self._check_database_version(c)
else:
self._create_database(c)
def _check_database_version(self, c):
# Tables already exist, check for the version # Tables already exist, check for the version
c.execute("select version from version") c.execute("select version from version")
version = c.fetchone()[0] version = c.fetchone()[0]
@ -66,7 +72,8 @@ class SQLiteSession(MemorySession):
self._auth_key = AuthKey(data=key) self._auth_key = AuthKey(data=key)
c.close() c.close()
else:
def _create_database(self, c):
# Tables don't exist, create new ones # Tables don't exist, create new ones
self._create_table( self._create_table(
c, c,