Skip to content

Commit

Permalink
fix search cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ciur committed Dec 15, 2024
1 parent 25c2c7f commit 510a9f5
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions papermerge/search/cli/index_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

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

SEARCH_URL = os.environ.get("PAPERMERGE__SEARCH__URL")
if not SEARCH_URL:
raise ValueError("missing PAPERMERGE__SEARCH__URL")

engine = create_engine(SEARCH_URL)
schema_manager = SchemaManager(engine, model=SearchIndex)


@app.command(name="apply")
def apply_cmd(dry_run: bool = False):
"""Apply schema fields"""
SEARCH_URL = os.environ.get("PAPERMERGE__SEARCH__URL")
if not SEARCH_URL:
raise ValueError("missing PAPERMERGE__SEARCH__URL")

engine = create_engine(SEARCH_URL)
schema_manager = SchemaManager(engine, model=SearchIndex)

if dry_run:
print_json(data=schema_manager.apply_dict_dump())
Expand All @@ -29,6 +28,13 @@ def apply_cmd(dry_run: bool = False):
@app.command(name="delete")
def delete_cmd(dry_run: bool = False):
"""Delete schema fields"""
SEARCH_URL = os.environ.get("PAPERMERGE__SEARCH__URL")
if not SEARCH_URL:
raise ValueError("missing PAPERMERGE__SEARCH__URL")

engine = create_engine(SEARCH_URL)
schema_manager = SchemaManager(engine, model=SearchIndex)

if dry_run:
print_json(data=schema_manager.delete_dict_dump())
else:
Expand All @@ -38,6 +44,13 @@ def delete_cmd(dry_run: bool = False):
@app.command(name="create")
def create_cmd(dry_run: bool = False):
"""Create schema fields"""
SEARCH_URL = os.environ.get("PAPERMERGE__SEARCH__URL")
if not SEARCH_URL:
raise ValueError("missing PAPERMERGE__SEARCH__URL")

engine = create_engine(SEARCH_URL)
schema_manager = SchemaManager(engine, model=SearchIndex)

if dry_run:
print_json(data=schema_manager.create_dict_dump())
else:
Expand Down

0 comments on commit 510a9f5

Please sign in to comment.