Skip to content

Commit

Permalink
Improved CLI Commands (#99)
Browse files Browse the repository at this point in the history
- `dbos init --config` will not configure migration commands as it does
not configure migrations.
- `dbos start` and `dbos migrate` now indicate where their commands come
from
  • Loading branch information
kraftp committed Sep 10, 2024
1 parent dc55341 commit 5be8775
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ def step_two():
print("Step two completed!")

@DBOS.workflow()
def workflow():
def dbos_workflow():
step_one()
for _ in range(5):
print("Press Control + \ to stop the app...")
DBOS.sleep(1)
step_two()

@app.get("/")
def endpoint():
workflow()
def fastapi_endpoint():
dbos_workflow()
```

Save the program into `main.py`, edit `dbos-config.yaml` to configure your Postgres connection settings, and start it with `fastapi run`.
Expand Down
7 changes: 6 additions & 1 deletion dbos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import tomlkit
import typer
from rich import print
from rich.prompt import Confirm, Prompt
from rich.prompt import Prompt
from typing_extensions import Annotated

from dbos import load_config
Expand All @@ -30,6 +30,7 @@ def on_windows() -> bool:
def start() -> None:
config = load_config()
start_commands = config["runtimeConfig"]["start"]
typer.echo("Executing start commands from 'dbos-config.yaml'")
for command in start_commands:
typer.echo(f"Executing: {command}")

Expand Down Expand Up @@ -129,9 +130,12 @@ def copy_template(src_dir: str, project_name: str, config_mode: bool) -> None:
"project_name": project_name,
"package_name": package_name,
"db_name": db_name,
"migration_command": "alembic upgrade head",
}

if config_mode:
ctx["package_name"] = "."
ctx["migration_command"] = "echo 'No migrations specified'"
copy_dbos_template(
os.path.join(src_dir, "dbos-config.yaml.dbos"),
os.path.join(dst_dir, "dbos-config.yaml"),
Expand Down Expand Up @@ -244,6 +248,7 @@ def migrate() -> None:
app_db.destroy()

# Next, run any custom migration commands specified in the configuration
typer.echo("Executing migration commands from 'dbos-config.yaml'")
try:
migrate_commands = (
config["database"]["migrate"]
Expand Down
2 changes: 1 addition & 1 deletion dbos/templates/hello/dbos-config.yaml.dbos
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ database:
password: ${PGPASSWORD}
app_db_name: ${db_name}
migrate:
- alembic upgrade head
- ${migration_command}
telemetry:
logs:
logLevel: INFO

0 comments on commit 5be8775

Please sign in to comment.