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
This commit is contained in:
Debanjum Singh Solanky 2023-08-01 21:41:08 -07:00
parent b9937549aa
commit 1812473d27
3 changed files with 11 additions and 6 deletions

View file

@ -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")

View file

@ -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"]:

View file

@ -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