Skip to content

Commit

Permalink
Combine CLI commands into one
Browse files Browse the repository at this point in the history
  • Loading branch information
mfisher87 committed Jul 18, 2024
1 parent 5ff8b70 commit f8773f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ browser to `http://localhost:8080` and enter:
### Run ingest
```bash
docker compose run cli init # Create empty tables (deleting any pre-existing ones)
docker compose run cli load # Load the tables from event files
docker compose run cli init
```
From a fast disk, this should take under 2 minutes.
Expand Down
25 changes: 13 additions & 12 deletions src/aross_stations_db/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy.orm import Session
from tqdm import tqdm

from aross_stations_db.config import CliLoadSettings, Settings
from aross_stations_db.config import CliLoadSettings
from aross_stations_db.db.setup import (
generate_event_objects,
load_events,
Expand All @@ -21,25 +21,26 @@ def cli() -> None:
pass


@click.option(
"--skip-load",
help="Skip loading data; only initialize tables.",
is_flag=True,
)
@cli.command
def init() -> None:
"""Create the database tables, dropping any that pre-exist."""
def init(skip_load: bool = False) -> None:
"""Load the database from files on disk."""
# TODO: False-positive. Remove type-ignore.
# See: https://github.com/pydantic/pydantic/issues/6713
config = Settings() # type:ignore[call-arg]
config = CliLoadSettings() # type:ignore[call-arg]

with Session(config.db_engine) as db_session:
recreate_tables(db_session)

logger.success("Database initialized")
logger.info("Database tables initialized")


@cli.command
def load() -> None:
"""Load the database tables from files on disk."""
# TODO: False-positive. Remove type-ignore.
# See: https://github.com/pydantic/pydantic/issues/6713
config = CliLoadSettings() # type:ignore[call-arg]
if skip_load:
logger.warning("Skipping data load.")
return

raw_stations = get_stations(config.stations_metadata_filepath)
raw_events = get_events(config.events_dir)
Expand Down

0 comments on commit f8773f2

Please sign in to comment.