Read the current schema version from the metadata table. Returns: int: The schema version (0 if metadata table doesn't exist, 1 if not set).
(conn: sqlite3.Connection)
| 14 | |
| 15 | |
| 16 | def get_schema_version(conn: sqlite3.Connection) -> int: |
| 17 | """Read the current schema version from the metadata table. |
| 18 | |
| 19 | Returns: |
| 20 | int: The schema version (0 if metadata table doesn't exist, 1 if not set). |
| 21 | """ |
| 22 | try: |
| 23 | row = conn.execute( |
| 24 | "SELECT value FROM metadata WHERE key = 'schema_version'" |
| 25 | ).fetchone() |
| 26 | if row is None: |
| 27 | return 1 |
| 28 | return int(row[0] if isinstance(row, (tuple, list)) else row["value"]) |
| 29 | except sqlite3.OperationalError: |
| 30 | # metadata table doesn't exist |
| 31 | return 0 |
| 32 | |
| 33 | |
| 34 | def _set_schema_version(conn: sqlite3.Connection, version: int) -> None: |
no outgoing calls