Notify the user about DB migrations

This commit is contained in:
flan 2019-03-14 00:45:29 +01:00
parent 4652642bcd
commit 5ad14b01b4
2 changed files with 25 additions and 0 deletions

View File

@ -35,6 +35,18 @@ class SqliteSessionManager(SimpleSessionManager):
SimpleSessionManager.__init__(self)
self.session_db_path = os.path.realpath(session_db_path)
self._ensure_schema_up_to_date()
def _ensure_schema_up_to_date(self):
conn = self._conn()
cursor = conn.cursor()
cursor.execute("SELECT * FROM sqlite_master "
"WHERE sql LIKE '%user VARCHAR PRIMARY KEY%' "
"AND tbl_name = 'session'")
res = cursor.fetchone()
conn.close()
if res is not None:
raise Exception("Outdated database schema, run utils/migrate_user_tables.py")
def _conn(self):
new = not os.path.exists(self.session_db_path)

View File

@ -44,7 +44,20 @@ class SqliteUserManager(SimpleUserManager):
def __init__(self, auth_db_path, collection_path=None):
SimpleUserManager.__init__(self, collection_path)
self.auth_db_path = os.path.realpath(auth_db_path)
self._ensure_schema_up_to_date()
def _ensure_schema_up_to_date(self):
conn = self._conn()
cursor = conn.cursor()
cursor.execute("SELECT * FROM sqlite_master "
"WHERE sql LIKE '%user VARCHAR PRIMARY KEY%' "
"AND tbl_name = 'auth'")
res = cursor.fetchone()
conn.close()
if res is not None:
raise Exception("Outdated database schema, run utils/migrate_user_tables.py")
# Default to using sqlite3 but overridable for sub-classes using other
# DB API 2 driver variants