From 21c9a81e0c53be96f9d8edde32b438fccbf2b794 Mon Sep 17 00:00:00 2001 From: bchanot Date: Mon, 16 Nov 2026 14:33:10 +0100 Subject: [PATCH] feat(supabase): db:sandbox migrate, forward only on the running sandbox --- docs/development/SUPABASE.md | 1 + scripts/db-sandbox.sh | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/docs/development/SUPABASE.md b/docs/development/SUPABASE.md index 8073ff20..440553aa 100644 --- a/docs/development/SUPABASE.md +++ b/docs/development/SUPABASE.md @@ -806,6 +806,7 @@ Docker. | `pnpm db:sandbox verify-e2e` | V1-2.3: a gateway (`nginx:1.31-alpine`, sandbox network only, no host port) and the real verification worker `faunosteo_worker:dev run --jobs sheet-verify` against the sandbox, then `packages/supabase/tests/sandbox/sheet-verification.sandbox.ts`; both containers removed at the end, the service key passed through a 600 file deleted at start | | `pnpm db:sandbox avatar-e2e` | V1-2.3: the same gateway, published on `127.0.0.1:57800` only and routing `/auth/v1/` too, the real worker `faunosteo_worker:dev run` (default mode: avatars and sweep, 5 s sweep, no quarantine grace, 512 MiB as the compose `worker`) against the sandbox, then `packages/supabase/tests/e2e/avatar-flow.e2e.ts` through that port; the suite's psql calls go to the sandbox database container, which it requires by name; its two accounts are made per run with random passwords and deleted after; both containers removed at the end | | `pnpm db:sandbox trial` / `trial-account ` / `trial-grant ` | V1-2.6 owner trial (`docs/development/V1-2-6_OWNER_TRIAL.md`): the app on `http://$FAUNOSTEO_TRIAL_HOST:5193` (default the LAN address of this machine, `127.0.0.1` = host-only; loopback or private IPv4 of an interface only, Host header allowlisted) behind a trial gateway on `127.0.0.1:57801` (refuses to start when `faunosteo_dbsandbox_trial_gateway` exists), a confirmed account (hidden password prompt), a catalogue right (email and kind checked, passed as psql variables; editor and publisher also get the admin role) | +| `pnpm db:sandbox migrate` | forward only on the running sandbox: `supabase migration up --db-url` applies the branch's pending migrations, nothing else (no reset, no seed, no container recreated, data kept); prints the last applied version before and after, a second run applies nothing | | `pnpm db:sandbox sql` / `down` | psql as postgres on stdin / remove the stack | Every CLI call passes `--db-url` with `sslmode=disable` (the sandbox has no diff --git a/scripts/db-sandbox.sh b/scripts/db-sandbox.sh index 360ebb63..c3b3b99c 100755 --- a/scripts/db-sandbox.sh +++ b/scripts/db-sandbox.sh @@ -265,6 +265,18 @@ cmd_up() { echo "== sandbox up ($mode): db 127.0.0.1:$PORT_DB, auth :$PORT_AUTH, rest :$PORT_REST, mail :$PORT_MAIL" } +# pnpm db:sandbox migrate: forward only, on the running sandbox; the branch's +# pending migrations and nothing else (no reset, no seed, no container recreated). +cmd_migrate() { + [ $# -eq 0 ] || die "migrate takes no argument" + docker ps --format '{{.Names}}' | grep -qx "$DB" || die "sandbox not up (pnpm db:sandbox up fresh)" + load_secrets + local last='select max(version) from supabase_migrations.schema_migrations' + echo "== before: $(sb_psql -t -A -c "$last")" + migrate_up . + echo "== after: $(sb_psql -t -A -c "$last")" +} + cmd_down() { docker rm -f "$AVATAR_WORKER" "$WORKER" "$TRIAL_GATEWAY" "$GATEWAY" "$REST" "$STORAGE" "$AUTH" "$MAIL" "$DB" >/dev/null 2>&1 || true docker network rm "$NET" >/dev/null 2>&1 || true @@ -521,6 +533,7 @@ case "${1:-}" in trial) cmd_trial ;; trial-account) shift; cmd_trial_account "$@" ;; trial-grant) shift; cmd_trial_grant "$@" ;; + migrate) shift; cmd_migrate "$@" ;; sql) load_secrets; sb_psql ;; *) sed -n '2,36p' "$0"; exit 1 ;; esac