diff --git a/metadex/db.py b/metadex/db.py index 2d95aa9..25ce0e5 100644 --- a/metadex/db.py +++ b/metadex/db.py @@ -105,15 +105,18 @@ class Db: engine: "Engine | None" = None is_dirty: bool = False - def __init__(self, path: Path): - self.open(path) + def __init__(self, path: Path, *, create_if_missing: bool = True): + self.open(path, create_if_missing=create_if_missing) def __del__(self): self.close() - def open(self, path: Path): + def open(self, path: Path, *, create_if_missing: bool = True): log.info("Using database: %a", str(path)) + if not create_if_missing and not path.exists(): + raise FileNotFoundError(f"File does not exist: {path!s}") + if self.engine: raise RuntimeError("DB already initialized.") diff --git a/metadex/metadex.py b/metadex/metadex.py index 2bc12e3..0a8325d 100644 --- a/metadex/metadex.py +++ b/metadex/metadex.py @@ -324,7 +324,7 @@ def ingest_db_file( context = _LogContext() - other_db = db.Db(db_file) + other_db = db.Db(db_file, create_if_missing=False) with db.transaction() as conn, other_db.transaction( force_rollback=True ) as other_conn: