Merge branch 'thebalaa-main'

This commit is contained in:
Kumi 2023-06-01 06:24:45 +00:00
commit 27078243a8
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -1,8 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
from typing import Optional from typing import Optional
from importlib import import_module from importlib import import_module
from sqlite3 import Connection as SQLiteConnection
from duckdb import DuckDBPyConnection
MAX_MIGRATION = 8 MAX_MIGRATION = 8
@ -11,11 +10,11 @@ MIGRATIONS = OrderedDict()
for i in range(1, MAX_MIGRATION + 1): for i in range(1, MAX_MIGRATION + 1):
MIGRATIONS[i] = import_module(f".migration_{i}", __package__).migration MIGRATIONS[i] = import_module(f".migration_{i}", __package__).migration
def get_version(db: DuckDBPyConnection) -> int: def get_version(db: SQLiteConnection) -> int:
"""Get the current database version. """Get the current database version.
Args: Args:
db (DuckDBPyConnection): Database connection. db (SQLiteConnection): Database connection.
Returns: Returns:
int: Current database version. int: Current database version.
@ -26,11 +25,11 @@ def get_version(db: DuckDBPyConnection) -> int:
except: except:
return 0 return 0
def migrate(db: DuckDBPyConnection, from_version: Optional[int] = None, to_version: Optional[int] = None) -> None: def migrate(db: SQLiteConnection, from_version: Optional[int] = None, to_version: Optional[int] = None) -> None:
"""Migrate the database to a specific version. """Migrate the database to a specific version.
Args: Args:
db (DuckDBPyConnection): Database connection. db (SQLiteConnection): Database connection.
from_version (Optional[int]): Version to migrate from. If None, the current version is used. from_version (Optional[int]): Version to migrate from. If None, the current version is used.
to_version (Optional[int]): Version to migrate to. If None, the latest version is used. to_version (Optional[int]): Version to migrate to. If None, the latest version is used.
""" """