Skip to content

Commit d2123ed

Browse files
authored
fix search cli (#569)
1 parent 25c2c7f commit d2123ed

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

docker/standard/entrypoint.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ exec_createsuperuser() {
2323
}
2424

2525
exec_index_schema_apply() {
26-
echo "RUNNING: exec_index_schema_apply"
27-
if [[ -z "${PAPERMERGE__SEARCH__URL}" ]]; then
28-
echo "env var PAPERMERGE__SEARCH__URL is NON-EMPTY... running..."
26+
echo "exec_index_schema_apply"
27+
if [ -n "${PAPERMERGE__SEARCH__URL}" ]; then
28+
# PAPERMERGE__SEARCH__URL has non-empty value
29+
echo "PAPERMERGE__SEARCH__URL=${PAPERMERGE__SEARCH__URL}"
30+
echo "Applying index schema..."
2931
cd /core_app && poetry run paper-cli index-schema apply
3032
fi
3133
}

papermerge/search/cli/index_schema.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,11 @@
88

99
app = typer.Typer(help="Index Schema Management")
1010

11-
SEARCH_URL = os.environ.get("PAPERMERGE__SEARCH__URL")
12-
if not SEARCH_URL:
13-
raise ValueError("missing PAPERMERGE__SEARCH__URL")
14-
15-
engine = create_engine(SEARCH_URL)
16-
schema_manager = SchemaManager(engine, model=SearchIndex)
17-
1811

1912
@app.command(name="apply")
2013
def apply_cmd(dry_run: bool = False):
2114
"""Apply schema fields"""
15+
schema_manager = get_schema_manager()
2216

2317
if dry_run:
2418
print_json(data=schema_manager.apply_dict_dump())
@@ -29,6 +23,8 @@ def apply_cmd(dry_run: bool = False):
2923
@app.command(name="delete")
3024
def delete_cmd(dry_run: bool = False):
3125
"""Delete schema fields"""
26+
schema_manager = get_schema_manager()
27+
3228
if dry_run:
3329
print_json(data=schema_manager.delete_dict_dump())
3430
else:
@@ -38,7 +34,18 @@ def delete_cmd(dry_run: bool = False):
3834
@app.command(name="create")
3935
def create_cmd(dry_run: bool = False):
4036
"""Create schema fields"""
37+
schema_manager = get_schema_manager()
38+
4139
if dry_run:
4240
print_json(data=schema_manager.create_dict_dump())
4341
else:
4442
schema_manager.create()
43+
44+
45+
def get_schema_manager():
46+
search_url = os.environ.get("PAPERMERGE__SEARCH__URL")
47+
if not search_url:
48+
raise ValueError("missing PAPERMERGE__SEARCH__URL")
49+
50+
engine = create_engine(search_url)
51+
return SchemaManager(engine, model=SearchIndex)

0 commit comments

Comments
 (0)