diff --git a/docs/development/SUPABASE.md b/docs/development/SUPABASE.md index 6590e86d..89a07428 100644 --- a/docs/development/SUPABASE.md +++ b/docs/development/SUPABASE.md @@ -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 | |---|---| diff --git a/scripts/db-sandbox.sh b/scripts/db-sandbox.sh index 21700f38..58d35e40 100755 --- a/scripts/db-sandbox.sh +++ b/scripts/db-sandbox.sh @@ -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 " ;; + 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 ; 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 " ;; esac start_rest echo "== sandbox up ($mode): db 127.0.0.1:$PORT_DB, auth :$PORT_AUTH, rest :$PORT_REST, mail :$PORT_MAIL"