Skip to content

Commit f8773f2

Browse files
committed
Combine CLI commands into one
1 parent 5ff8b70 commit f8773f2

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ browser to `http://localhost:8080` and enter:
153153
### Run ingest
154154
155155
```bash
156-
docker compose run cli init # Create empty tables (deleting any pre-existing ones)
157-
docker compose run cli load # Load the tables from event files
156+
docker compose run cli init
158157
```
159158
160159
From a fast disk, this should take under 2 minutes.

src/aross_stations_db/cli.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from sqlalchemy.orm import Session
44
from tqdm import tqdm
55

6-
from aross_stations_db.config import CliLoadSettings, Settings
6+
from aross_stations_db.config import CliLoadSettings
77
from aross_stations_db.db.setup import (
88
generate_event_objects,
99
load_events,
@@ -21,25 +21,26 @@ def cli() -> None:
2121
pass
2222

2323

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

3136
with Session(config.db_engine) as db_session:
3237
recreate_tables(db_session)
3338

34-
logger.success("Database initialized")
39+
logger.info("Database tables initialized")
3540

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

4445
raw_stations = get_stations(config.stations_metadata_filepath)
4546
raw_events = get_events(config.events_dir)

0 commit comments

Comments
 (0)