Command 'recreate-db' is not found in your path
arunkhattri opened this issue · comments
though it's a PdmUsageError, however couldn't find the solution. Hope you can help me out. Chapter 2, connecting to the database...
my pyproject.toml
[tool.pdm.scripts]
recreate-db-base = "quart --app src/backend/run.py recreate_db"
recreate_db = {composite = ["recreate-db-base"], env_file = "development.env"}
test = {composite = ["recreate-db-base", "pytest tests/"], env_file = "testing.env"}
relevant run.py section
@app.cli.command("recreate_db")
def recreate_db() -> None:
db_url = urlparse(os.environ["TOZO_QUART_DB_DATABASE_URL"])
call( # nosec
[
"psql",
"-U",
"postgres",
"-c",
f"DROP DATABASE IF EXISTS {db_url.path.removeprefix('/')}",
]
)
call( # nosec
["psql", "-U", "postgres", "-c", f"DROP USER IF EXISTS {db_url.username}"]
)
call( # nosec
[
"psql",
"-U",
"postgres",
"-c",
f"CREATE USER {db_url.username} LOGIN PASSWORD '{db_url.password}' CREATEDB",
]
)
call( # nosec
[
"psql",
"-U",
"postgres",
"-c",
f"CREATE DATABASE {db_url.path.removeprefix('/')}",
]
)
related to pdm ...
pdm info
PDM version:
2.11.2
Python Interpreter:
/home/arunkhattri/github/arunkhattri/tozo/backend/.venv/bin/python (3.11)
Project Root:
/home/arunkhattri/github/arunkhattri/tozo/backend
This looks to be a simple typo, @app.cli.command("recreate_db")
should be @app.cli.command("recreate-db")
(note the _
to -
change). Please reopen if this doesn't solve the issue.
Thanks for buying my book.
pyproject.toml needs to be modified accordingly
recreate-db-base = "quart --app src/backend/run.py recreate-db"