From a39de3db835bb71ab3ecce33f7caebfdd0a2b95f Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Thu, 21 Nov 2024 09:45:16 +0100 Subject: [PATCH] database.files_db:FileDB - do not init automatically, add parameter to check if database is initialized and raise an error if not --- acacore/database/files_db.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/acacore/database/files_db.py b/acacore/database/files_db.py index e0781c71..68997f5f 100644 --- a/acacore/database/files_db.py +++ b/acacore/database/files_db.py @@ -2,6 +2,7 @@ from os import PathLike from pathlib import Path from sqlite3 import Connection +from sqlite3 import DatabaseError from typing import Type from uuid import UUID @@ -52,6 +53,7 @@ def __init__( cached_statements: int = 100, uri: bool = False, check_version: bool = True, + check_initialisation: bool = False, ) -> None: """ A class that handles the SQLite database used by AArhus City Archives to process data archives. @@ -203,13 +205,13 @@ def __init__( ], ) - if self.is_initialised(check_views=False, check_indices=False): - if check_version: - from acacore.database.upgrade import is_latest + if check_initialisation and not self.is_initialised(check_views=False, check_indices=False): + raise DatabaseError("Database is not initialised") - is_latest(self, raise_on_difference=True) - else: - self.init() + if check_version and self.is_initialised(): + from acacore.database.upgrade import is_latest + + is_latest(self, raise_on_difference=True) def is_initialised(self, *, check_views: bool = True, check_indices: bool = True) -> bool: """