diff --git a/app/database/db.py b/app/database/db.py index 0377c8dfb..850a28c9c 100644 --- a/app/database/db.py +++ b/app/database/db.py @@ -4,7 +4,7 @@ import shutil from app.logger import log_startup_warning from utils.install_util import get_missing_requirements_message from filelock import FileLock, Timeout -from comfy.cli_args import args +from comfy.cli_args import args, database_default_path _DB_AVAILABLE = False Session = None @@ -73,8 +73,6 @@ def get_database_url(): def get_legacy_default_db_path(): - from comfy.cli_args import database_default_path - return database_default_path @@ -101,7 +99,10 @@ def copy_legacy_default_db(db_path): return shutil.copy(legacy_db_path, db_path) - logging.info(f"Copied legacy database from '{legacy_db_path}' to '{db_path}'") + os.replace(legacy_db_path, legacy_db_path + ".bak") + logging.info( + f"Copied legacy database from '{legacy_db_path}' to '{db_path}' and renamed the original to '{legacy_db_path}.bak'" + ) def prepare_file_db_path(db_path): diff --git a/tests-unit/app_test/database_path_test.py b/tests-unit/app_test/database_path_test.py index 543c0ba10..7966d700e 100644 --- a/tests-unit/app_test/database_path_test.py +++ b/tests-unit/app_test/database_path_test.py @@ -72,7 +72,8 @@ def test_legacy_default_database_is_copied_to_effective_user_directory(monkeypat db.copy_legacy_default_db(str(user_dir / "comfyui.db")) assert (user_dir / "comfyui.db").read_bytes() == b"legacy db" - assert legacy_db.read_bytes() == b"legacy db" + assert not legacy_db.exists() + assert legacy_db.with_suffix(".db.bak").read_bytes() == b"legacy db" def test_legacy_default_database_does_not_overwrite_existing_effective_db(monkeypatch, tmp_path):