mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 13:23:15 +00:00
Merge pull request #329 from khoj-ai/create-schema-migration-func-and-reindex-to-fix-corruption
Create Schema Migrator and Reindex to Apply Index Corruption Fixes -83e1088Manage `khoj.yml' config migrations on app start. Version the `khoj.yml' schema -429e1b4Regenerate index to apply corruption fixes on first run of this khoj version Otherwise users would need to manually re-index their contents with khoj
This commit is contained in:
@@ -5,7 +5,7 @@ from importlib.metadata import version
|
|||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from khoj.utils.helpers import resolve_absolute_path
|
from khoj.utils.helpers import resolve_absolute_path
|
||||||
from khoj.utils.yaml import parse_config_from_file
|
from khoj.utils.yaml import load_config_from_file, parse_config_from_file, save_config_to_file
|
||||||
|
|
||||||
|
|
||||||
def cli(args=None):
|
def cli(args=None):
|
||||||
@@ -34,9 +34,10 @@ def cli(args=None):
|
|||||||
|
|
||||||
args = parser.parse_args(args)
|
args = parser.parse_args(args)
|
||||||
|
|
||||||
|
args.version_no = version("khoj-assistant")
|
||||||
if args.version:
|
if args.version:
|
||||||
# Show version of khoj installed and exit
|
# Show version of khoj installed and exit
|
||||||
print(version("khoj-assistant"))
|
print(args.version_no)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
# Normalize config_file path to absolute path
|
# Normalize config_file path to absolute path
|
||||||
@@ -45,6 +46,22 @@ def cli(args=None):
|
|||||||
if not args.config_file.exists():
|
if not args.config_file.exists():
|
||||||
args.config = None
|
args.config = None
|
||||||
else:
|
else:
|
||||||
|
args = migrate_config(args)
|
||||||
args.config = parse_config_from_file(args.config_file)
|
args.config = parse_config_from_file(args.config_file)
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_config(args):
|
||||||
|
raw_config = load_config_from_file(args.config_file)
|
||||||
|
|
||||||
|
# Add version to khoj config schema
|
||||||
|
if "version" not in raw_config:
|
||||||
|
raw_config["version"] = args.version_no
|
||||||
|
save_config_to_file(raw_config, args.config_file)
|
||||||
|
|
||||||
|
# regenerate khoj index on first start of this version
|
||||||
|
# this should refresh index and apply index corruption fixes from #325
|
||||||
|
args.regenerate = True
|
||||||
|
|
||||||
|
return args
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ class FullConfig(ConfigBase):
|
|||||||
search_type: Optional[SearchConfig] = None
|
search_type: Optional[SearchConfig] = None
|
||||||
processor: Optional[ProcessorConfig] = None
|
processor: Optional[ProcessorConfig] = None
|
||||||
app: Optional[AppConfig] = AppConfig(should_log_telemetry=True)
|
app: Optional[AppConfig] = AppConfig(should_log_telemetry=True)
|
||||||
|
version: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class SearchResponse(ConfigBase):
|
class SearchResponse(ConfigBase):
|
||||||
|
|||||||
Reference in New Issue
Block a user