fix(supabase): refuse bad sandbox arguments before starting anything

pnpm db:sandbox up with an unknown mode or a missing or malformed upgrade version started four containers and wrote the secrets before refusing. The mode and the version (fourteen digits) are now checked first.
This commit is contained in:
bchanot committed 2026-10-25 22:20:55 +01:00
1 parent 5bc6631b6e
commit 57922e0902
2 files changed
+11 -3

No files matched your search

+3 -1
View File
@@ -334,7 +334,9 @@ secret and keys are generated at each `up` into a 600 file under
repository), with 600 env files that hand them to the containers; deleted by
`down`, never printed, never on a command line (the CLI and psql read
`PGPASSWORD` from the environment). An incomplete secrets file stops the
script before any CLI call. Works with rootless Docker.
script before any CLI call, and a wrong `up` mode or version (fourteen
digits) is refused before any container or secret exists. Works with rootless
Docker.
| Command | What it does |
|---|---|
+8 -2
View File
@@ -173,6 +173,13 @@ gotrue_accounts() {
cmd_up() {
local mode="${1:-}"
# Arguments checked before anything starts: a refusal leaves no container or secret.
case "$mode" in
fresh) ;;
upgrade) [[ "${2:-}" =~ ^[0-9]{14}$ ]] \
|| die "up upgrade needs the first new migration version, e.g. 20261025100000" ;;
*) die "up fresh | up upgrade <version>" ;;
esac
docker ps -a --format '{{.Names}}' | grep -q '^faunosteo_dbsandbox_' && die "already up (pnpm db:sandbox down)"
new_secrets
start_services
@@ -180,7 +187,7 @@ cmd_up() {
fresh)
migrate_up . ; seed ;;
upgrade)
local version="${2:?upgrade needs the first new migration version, e.g. 20261025100000}"
local version="$2"
# A CLI workdir holding only the migrations before <version>; kept in the
# state folder and refilled at each upgrade run (the CLI writes .temp there).
local base="$STATE/upgrade-base"
@@ -194,7 +201,6 @@ cmd_up() {
seed; gotrue_accounts
echo "== before: $(sb_psql -t -A -c 'select count(*) from public.profiles') profiles"
migrate_up . ;;
*) die "up fresh | up upgrade <version>" ;;
esac
start_rest
echo "== sandbox up ($mode): db 127.0.0.1:$PORT_DB, auth :$PORT_AUTH, rest :$PORT_REST, mail :$PORT_MAIL"