mirror of
https://github.com/penpot/penpot.git
synced 2026-10-03 01:06:14 +00:00
* ✨ Isolate backend-test database per devenv instance Each wsN now gets its own backend-test database (penpot_test_wsN) and Valkey DB (6+N) on the shared infra, so parallel test runs no longer wipe each other. The main database stays shared on purpose. manage.sh creates the test database on bring-up and passes PENPOT_TEST_* into the main container. Test helpers already read those vars, so no runtime code changes. scripts/psql and db-schema gain --ws. AI-assisted-by: muse-spark-1.3-contributor-free * 🐛 Fix per-instance test database creation on bring-up psql -c does not reliably mix SQL with psql-only commands, so the CREATE DATABASE ... WHERE NOT EXISTS ... \gexec one-liner never ran. Use two plain SQL round-trips instead (check pg_database, then CREATE DATABASE) and print what happens, so a future failure shows up in the bring-up output. AI-assisted-by: muse-spark-1.3-contributor-free
66 lines
1.5 KiB
Bash
Executable File
66 lines
1.5 KiB
Bash
Executable File
#!/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}"
|
|
TEST=false
|
|
WS=""
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--test)
|
|
DB="penpot_test"
|
|
TEST=true
|
|
shift
|
|
;;
|
|
--ws)
|
|
WS="$2"
|
|
shift 2
|
|
;;
|
|
--ws*)
|
|
WS="${1#--ws}"
|
|
shift
|
|
;;
|
|
--host|-h)
|
|
HOST="$2"
|
|
shift 2
|
|
;;
|
|
--user|-U)
|
|
USER="$2"
|
|
shift 2
|
|
;;
|
|
--db|-d)
|
|
DB="$2"
|
|
shift 2
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# --ws selects one instance's isolated backend-test database
|
|
# (penpot_test on ws0, penpot_test_wsN on wsN). It only applies together
|
|
# with --test because the main database is shared by all instances.
|
|
if [[ -n "$WS" ]]; then
|
|
if [[ "$WS" =~ ^ws([0-9]+)$ ]]; then
|
|
WS="${BASH_REMATCH[1]}"
|
|
fi
|
|
if [[ ! "$WS" =~ ^[0-9]+$ ]]; then
|
|
echo "Invalid --ws value: '$WS' (expected a non-negative integer, e.g. --ws 1)" >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$TEST" != "true" ]]; then
|
|
echo "--ws only applies together with --test (the main database is shared by all instances)." >&2
|
|
exit 1
|
|
fi
|
|
if [[ "$WS" != "0" ]]; then
|
|
DB="penpot_test_ws${WS}"
|
|
fi
|
|
fi
|
|
|
|
export PGPASSWORD="$PASSWORD"
|
|
exec pg_dump -h "$HOST" -U "$USER" -d "$DB" --schema-only --no-owner --no-privileges "$@"
|