From 1812473d27e288bda47a235111bf591633a44594 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 1 Aug 2023 21:41:08 -0700 Subject: [PATCH] Extract new schema version for each migration script into a variable This should ease readability, indicates which version this migration script will update the schema to once applied --- src/khoj/migrations/migrate_offline_model.py | 11 +++++++---- .../migrations/migrate_processor_config_openai.py | 3 ++- src/khoj/migrations/migrate_version.py | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/khoj/migrations/migrate_offline_model.py b/src/khoj/migrations/migrate_offline_model.py index e0f6a06b..853ceb4b 100644 --- a/src/khoj/migrations/migrate_offline_model.py +++ b/src/khoj/migrations/migrate_offline_model.py @@ -8,12 +8,15 @@ logger = logging.getLogger(__name__) def migrate_offline_model(args): + schema_version = "0.10.1" raw_config = load_config_from_file(args.config_file) - version_no = raw_config.get("version") + previous_version = raw_config.get("version") - if version_no is None or version.parse(version_no) < version.parse("0.10.1"): - logger.info(f"Migrating offline model used for version {version_no} to latest version for {args.version_no}") - raw_config["version"] = "0.10.1" + if previous_version is None or version.parse(previous_version) < version.parse("0.10.1"): + logger.info( + f"Migrating offline model used for version {previous_version} to latest version for {args.version_no}" + ) + raw_config["version"] = schema_version # If the user has downloaded the offline model, remove it from the cache. offline_model_path = os.path.expanduser("~/.cache/gpt4all/llama-2-7b-chat.ggmlv3.q4_K_S.bin") diff --git a/src/khoj/migrations/migrate_processor_config_openai.py b/src/khoj/migrations/migrate_processor_config_openai.py index 9d51d152..c25e5306 100644 --- a/src/khoj/migrations/migrate_processor_config_openai.py +++ b/src/khoj/migrations/migrate_processor_config_openai.py @@ -34,6 +34,7 @@ from khoj.utils.yaml import load_config_from_file, save_config_to_file def migrate_processor_conversation_schema(args): + schema_version = "0.10.0" raw_config = load_config_from_file(args.config_file) if "processor" not in raw_config: @@ -48,7 +49,7 @@ def migrate_processor_conversation_schema(args): if current_openai_api_key is None and current_chat_model is None: return args - raw_config["version"] = "0.10.0" + raw_config["version"] = schema_version # Add enable_offline_chat to khoj config schema if "enable-offline-chat" not in raw_config["processor"]["conversation"]: diff --git a/src/khoj/migrations/migrate_version.py b/src/khoj/migrations/migrate_version.py index e0a8c793..de8b9571 100644 --- a/src/khoj/migrations/migrate_version.py +++ b/src/khoj/migrations/migrate_version.py @@ -2,11 +2,12 @@ from khoj.utils.yaml import load_config_from_file, save_config_to_file def migrate_config_to_version(args): + schema_version = "0.9.0" raw_config = load_config_from_file(args.config_file) # Add version to khoj config schema if "version" not in raw_config: - raw_config["version"] = "0.9.0" + raw_config["version"] = schema_version save_config_to_file(raw_config, args.config_file) # regenerate khoj index on first start of this version