Skip to content

Commit 5be8775

Browse files
committed
Improved CLI Commands (#99)
- `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
1 parent dc55341 commit 5be8775

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ def step_two():
6868
print("Step two completed!")
6969

7070
@DBOS.workflow()
71-
def workflow():
71+
def dbos_workflow():
7272
step_one()
7373
for _ in range(5):
7474
print("Press Control + \ to stop the app...")
7575
DBOS.sleep(1)
7676
step_two()
7777

7878
@app.get("/")
79-
def endpoint():
80-
workflow()
79+
def fastapi_endpoint():
80+
dbos_workflow()
8181
```
8282

8383
Save the program into `main.py`, edit `dbos-config.yaml` to configure your Postgres connection settings, and start it with `fastapi run`.

dbos/cli.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import tomlkit
1313
import typer
1414
from rich import print
15-
from rich.prompt import Confirm, Prompt
15+
from rich.prompt import Prompt
1616
from typing_extensions import Annotated
1717

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

@@ -129,9 +130,12 @@ def copy_template(src_dir: str, project_name: str, config_mode: bool) -> None:
129130
"project_name": project_name,
130131
"package_name": package_name,
131132
"db_name": db_name,
133+
"migration_command": "alembic upgrade head",
132134
}
133135

134136
if config_mode:
137+
ctx["package_name"] = "."
138+
ctx["migration_command"] = "echo 'No migrations specified'"
135139
copy_dbos_template(
136140
os.path.join(src_dir, "dbos-config.yaml.dbos"),
137141
os.path.join(dst_dir, "dbos-config.yaml"),
@@ -244,6 +248,7 @@ def migrate() -> None:
244248
app_db.destroy()
245249

246250
# Next, run any custom migration commands specified in the configuration
251+
typer.echo("Executing migration commands from 'dbos-config.yaml'")
247252
try:
248253
migrate_commands = (
249254
config["database"]["migrate"]

dbos/templates/hello/dbos-config.yaml.dbos

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ database:
1515
password: ${PGPASSWORD}
1616
app_db_name: ${db_name}
1717
migrate:
18-
- alembic upgrade head
18+
- ${migration_command}
1919
telemetry:
2020
logs:
2121
logLevel: INFO

0 commit comments

Comments
 (0)