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
|
engine: "Engine | None" = None
|
||||||
is_dirty: bool = False
|
is_dirty: bool = False
|
||||||
|
|
||||||
def __init__(self, path: Path):
|
def __init__(self, path: Path, *, create_if_missing: bool = True):
|
||||||
self.open(path)
|
self.open(path, create_if_missing=create_if_missing)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def open(self, path: Path):
|
def open(self, path: Path, *, create_if_missing: bool = True):
|
||||||
log.info("Using database: %a", str(path))
|
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:
|
if self.engine:
|
||||||
raise RuntimeError("DB already initialized.")
|
raise RuntimeError("DB already initialized.")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,7 @@ def ingest_db_file(
|
||||||
|
|
||||||
context = _LogContext()
|
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(
|
with db.transaction() as conn, other_db.transaction(
|
||||||
force_rollback=True
|
force_rollback=True
|
||||||
) as other_conn:
|
) as other_conn:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue