Exemplo n.º 1
0
def update_database_file(wallet_path: str) -> None:
    if wallet_path.endswith(DATABASE_EXT):
        raise DatabaseMigrationError("wallet path is not base path")

    db_path = wallet_path + DATABASE_EXT
    if not os.path.exists(db_path):
        raise DatabaseMigrationError("wallet database does not exist")

    db = sqlite3.connect(db_path)
    update_database(db)
    db.close()
Exemplo n.º 2
0
def create_database_file(wallet_path: str) -> None:
    if wallet_path.endswith(DATABASE_EXT):
        raise DatabaseMigrationError("wallet path is not base path")
    if 22 != MIGRATION_FIRST:
        raise DatabaseMigrationError(
            "constant MIGRATION_FIRST differs from local version")
    db_path = wallet_path + DATABASE_EXT
    if os.path.exists(db_path):
        raise DatabaseMigrationError("wallet database already exists")

    db = sqlite3.connect(db_path)
    create_database(db)
    db.close()

    update_database_file(wallet_path)
Exemplo n.º 3
0
def _get_migration(db: sqlite3.Connection) -> int:
    cursor = db.execute("SELECT value FROM WalletData WHERE key='migration'")
    row = cursor.fetchone()
    if row is None:
        raise DatabaseMigrationError(
            "wallet database migration metadata not present")
    return json.loads(row[0])
Exemplo n.º 4
0
def _ensure_matching_migration(db: sqlite3.Connection,
                               expected_migration: int):
    migration = _get_migration(db)
    if migration != expected_migration:
        raise DatabaseMigrationError(
            "wallet database migration mismatch, expected "
            f"{expected_migration}, got {migration}")
Exemplo n.º 5
0
def create_database_file(wallet_path: str) -> None:
    if wallet_path.endswith(DATABASE_EXT):
        raise DatabaseMigrationError("wallet path is not base path")
    if 22 != MIGRATION_FIRST:
        raise DatabaseMigrationError(
            "constant MIGRATION_FIRST differs from local version")
    db_path = wallet_path + DATABASE_EXT
    if os.path.exists(db_path):
        raise DatabaseMigrationError("wallet database already exists")

    # Python sqlite bindings automatically enter a transaction which prevents the PRAGMA from
    # exiting, which is why we use no isolation level.
    db = sqlite3.connect(db_path,
                         check_same_thread=False,
                         isolation_level=None)
    db.execute(f"PRAGMA journal_mode=WAL;")
    create_database(db)
    db.close()

    update_database_file(wallet_path)