diff --git a/.serena/memories/backend/core.md b/.serena/memories/backend/core.md index 34a272dedc..d815f69070 100644 --- a/.serena/memories/backend/core.md +++ b/.serena/memories/backend/core.md @@ -39,6 +39,9 @@ Backend RPC command areas without focused memories include access tokens, binfil Database migrations live in `backend/src/app/migrations/`; pure SQL migrations are under `backend/src/app/migrations/sql/`. SQL filenames conventionally start with a sequence and verb/table description, e.g. `0026-mod-profile-table-add-is-active-field`. Applied migrations are tracked in the `migrations` table. +For interactive PostgreSQL access with correct dev defaults, use `tools/psql`; to dump +the current DDL schema, use `tools/db-schema` (see `mem:tools/psql`). + For deeper details on transaction semantics, advisory locks, Transit vs JSON helpers, and dev/test DB URLs: `mem:backend/rpc-db-worker-subtleties`. ## Background tasks diff --git a/.serena/memories/critical-info.md b/.serena/memories/critical-info.md index 23881c6f89..33ccf8a8ad 100644 --- a/.serena/memories/critical-info.md +++ b/.serena/memories/critical-info.md @@ -45,7 +45,8 @@ module. You can read it from `mem:/core` tmux session lifecycle, MinIO provisioning, or anything in `manage.sh`'s `*-devenv` commands, read `mem:devenv/core`. - `tools/` contains standalone dev utilities: `nrepl-eval.mjs` (backend REPL eval), - `paren-repair.bb` (delimiter-error fixer, see `mem:tools/paren-repair`), and + `paren-repair.bb` (delimiter-error fixer, see `mem:tools/paren-repair`), + `psql` / `db-schema` (PostgreSQL client and schema dump wrappers, see `mem:tools/psql`), and `taiga.py` / `gh.py` (issue management helpers). - `experiments/` contains standalone experimental HTML/JS/scripts; treat it as non-core unless the user explicitly asks about it. - `sample_media/` contains sample image/icon media and config used as fixtures/demo material; do not infer app behavior from it. diff --git a/.serena/memories/tools/psql.md b/.serena/memories/tools/psql.md new file mode 100644 index 0000000000..c502b4c1e9 --- /dev/null +++ b/.serena/memories/tools/psql.md @@ -0,0 +1,51 @@ +# PostgreSQL client wrapper + +`tools/psql` is a wrapper around the `psql` command with defaults preconfigured +for the Penpot development environment. + +## When to use + +- Running SQL queries against the dev database (`penpot`) or test database + (`penpot_test`). +- Inspecting table structures, running migrations manually, or debugging + database state. +- Any time you need PostgreSQL access and want the correct host/user/password + without typing them each time. + +## How to use + +```bash +# Interactive session (penpot database) +tools/psql + +# Interactive session (penpot_test database) +tools/psql --test + +# Inline query (penpot) +tools/psql -c "SELECT 1" + +# Inline query (penpot_test) +tools/psql --test -c "SELECT 1" + +# Override defaults +tools/psql -h other-host -U other-user -d other-db + +# Pipe SQL from a file +tools/psql -f some-query.sql +``` + +All standard `psql` flags are passed through after the wrapper's own flags. + +## Defaults + +| Setting | Default | Env override | +|----------|-----------|---------------------| +| Host | `postgres` | `PENPOT_DB_HOST` | +| User | `penpot` | `PENPOT_DB_USER` | +| Password | `penpot` | `PENPOT_DB_PASSWORD` | +| Database | `penpot` | `PENPOT_DB_NAME` | + +## See also + +`tools/db-schema` — a companion script that dumps the current DDL schema +using `pg_dump --schema-only`, with the same defaults and `--test` flag. diff --git a/tools/db-schema b/tools/db-schema new file mode 100755 index 0000000000..6cf2a8c710 --- /dev/null +++ b/tools/db-schema @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -euo pipefail + +HOST="${PENPOT_DB_HOST:-postgres}" +USER="${PENPOT_DB_USER:-penpot}" +PASSWORD="${PENPOT_DB_PASSWORD:-penpot}" +DB="${PENPOT_DB_NAME:-penpot}" + +while [[ $# -gt 0 ]]; do + case "$1" in + --test) + DB="penpot_test" + shift + ;; + --host|-h) + HOST="$2" + shift 2 + ;; + --user|-U) + USER="$2" + shift 2 + ;; + --db|-d) + DB="$2" + shift 2 + ;; + *) + break + ;; + esac +done + +export PGPASSWORD="$PASSWORD" +exec pg_dump -h "$HOST" -U "$USER" -d "$DB" --schema-only --no-owner --no-privileges "$@" diff --git a/tools/psql b/tools/psql new file mode 100755 index 0000000000..03dee3be19 --- /dev/null +++ b/tools/psql @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +set -euo pipefail + +HOST="${PENPOT_DB_HOST:-postgres}" +USER="${PENPOT_DB_USER:-penpot}" +PASSWORD="${PENPOT_DB_PASSWORD:-penpot}" +DB="${PENPOT_DB_NAME:-penpot}" + +while [[ $# -gt 0 ]]; do + case "$1" in + --test) + DB="penpot_test" + shift + ;; + --host|-h) + HOST="$2" + shift 2 + ;; + --user|-U) + USER="$2" + shift 2 + ;; + --db|-d) + DB="$2" + shift 2 + ;; + *) + break + ;; + esac +done + +export PGPASSWORD="$PASSWORD" +exec psql -h "$HOST" -U "$USER" -d "$DB" "$@"