fix creating empty DB when ingest target does not exist
This commit is contained in:
parent
b6670191e5
commit
1e21fb08a5
2 changed files with 7 additions and 4 deletions
|
|
@ -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.")
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue