LEGAL_EXTENSIONS = {'webm', 'mp4', 'mkv'}
# tables to create database with
+EXPECTED_DB_VERSION = 0
+SQL_DB_VERSION = SqlText('PRAGMA user_version')
SCRIPT_INIT_DB = '''
CREATE TABLE yt_queries (
id TEXT PRIMARY KEY,
class NotFoundException(Exception):
- """Call on expected data missing, e.g. DB fetches finding nothing."""
+ """Raise on expected data missing, e.g. DB fetches finding nothing."""
class CantWriteException(Exception):
- """Call when there's an obstacle to expected writing of data."""
+ """Raise when there's an obstacle to expected writing of data."""
+
+
+class HandledException(Exception):
+ """Raise in any other case where we know what's happening."""
def _ensure_expected_dirs(expected_dirs: list[PathStr]) -> None:
'into, did you run install.py?')
with sql_connect(self._path) as conn:
conn.executescript(SCRIPT_INIT_DB)
+ conn.execute(f'{SQL_DB_VERSION} = {EXPECTED_DB_VERSION}')
+ with sql_connect(self._path) as conn:
+ db_version = list(conn.execute(SQL_DB_VERSION))[0][0]
+ if db_version != EXPECTED_DB_VERSION:
+ raise HandledException(f'wrong database version {db_version}, '
+ f'expected: {EXPECTED_DB_VERSION}')
self._conn = sql_connect(self._path)
def exec(self, sql: SqlText, inputs: tuple[Any, ...] = tuple()) -> Cursor: