diff --git a/ankisyncd/sessions.py b/ankisyncd/sessions.py index 7a7b2d4..9e5855a 100644 --- a/ankisyncd/sessions.py +++ b/ankisyncd/sessions.py @@ -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) diff --git a/ankisyncd/users.py b/ankisyncd/users.py index da2af36..4b57060 100644 --- a/ankisyncd/users.py +++ b/ankisyncd/users.py @@ -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