📚 Clarify PostgreSQL wrapper destinations

Document workspace test database selection and correct the default host
and tool limitations to prevent queries against the wrong database.

AI-assisted-by: gpt-6.1-terra
This commit is contained in:
Andrey Antukh 2026-11-23 22:19:42 +00:00
parent df1767c25f
commit c3a407286a

View File

@ -1,47 +1,5 @@
# Psql
# PostgreSQL wrappers
`scripts/psql` is a wrapper around `psql` that connects to the Penpot PostgreSQL
database using environment variables (`PENPOT_DB_HOST`, `PENPOT_DB_USER`,
`PENPOT_DB_PASSWORD`, `PENPOT_DB_NAME`) with sensible defaults for local
development.
## When to use
- Running ad-hoc SQL queries against the Penpot database.
- Inspecting schema, migrations, or data during development or debugging.
## How to use (CLI)
```bash
# Default connection (penpot db, localhost)
scripts/psql -c "SELECT version();"
# Test database (ws0)
scripts/psql --test -c "SELECT * FROM migrations;"
# Isolated test database of another instance (ws1+)
scripts/psql --test --ws 1 -c "SELECT * FROM migrations;"
# Custom host/user/database
scripts/psql --host myhost --user myuser --db mydb
```
`--ws N` only applies together with `--test` (the main database is
shared by all instances): it selects `penpot_test` on `--ws 0` and
`penpot_test_wsN` on `--ws N`. `scripts/db-schema` accepts the same flags.
`scripts/psql` must be invoked from the repo root so the path resolves.
## Native Tool Available (OpenCode V2)
A native OpenCode V2 tool `penpot-psql` is available. It is defined in
`.opencode/plugins/penpot.js` and registered through `setup()`. The LLM can
call it directly with:
- `sql`: SQL command string to execute
- `test`: Boolean flag to use the `penpot_test` database
Example usage by the LLM:
```
penpot-psql(sql="SELECT version();")
penpot-psql(sql="SELECT * FROM migrations;", test=true)
```
- `scripts/psql` invokes `psql`; `scripts/db-schema` invokes schema-only `pg_dump`. Both use `PENPOT_DB_HOST`, `PENPOT_DB_USER`, `PENPOT_DB_PASSWORD` and `PENPOT_DB_NAME`, not the backend test URI. The default host is `postgres`; check the effective destination before executing SQL.
- Both wrappers accept `--test --ws N` (also `--ws wsN`): workspace 0 selects `penpot_test`, and workspace N selects `penpot_test_wsN`. `--ws` without `--test` is rejected because the main database is shared. Check the actual `PENPOT_TEST_DATABASE_URI` for the workspace rather than assuming the wrapper's defaults match it; see `mem:devenv/core`.
- The `penpot-psql` tool's `test` option selects `penpot_test`; it has no workspace selector. Consult the active tool catalog for its invocation and use the wrapper or another explicitly configured client when the target differs.