chore(supabase): sandbox upgrade can stop at an intermediate migration
`pnpm db:sandbox up upgrade <version> <then>` applies the migrations before <then> over the seeded older base, reports the workspaces, then the rest: the path of a DEV database that took M1 first and M2 + M3 later.
This commit is contained in:
1 parent
0826ecf383
commit
2dc04bcfba
1 file changed
+27
-16
+27
-16
@@ -6,8 +6,10 @@
|
|||||||
# `down` removes only the containers and network named below.
|
# `down` removes only the containers and network named below.
|
||||||
#
|
#
|
||||||
# pnpm db:sandbox up fresh all migrations, then the seeds (= db reset)
|
# pnpm db:sandbox up fresh all migrations, then the seeds (= db reset)
|
||||||
# pnpm db:sandbox up upgrade <version> migrations before <version>, seeds, two
|
# pnpm db:sandbox up upgrade <version> [<then>]
|
||||||
# GoTrue accounts, then `migration up` (= DEV path)
|
# migrations before <version>, seeds, two GoTrue
|
||||||
|
# accounts, then `migration up` (= DEV path); with
|
||||||
|
# <then>, the migrations before <then> first, then the rest
|
||||||
# pnpm db:sandbox test-db the pgTAP files (`supabase test db`)
|
# pnpm db:sandbox test-db the pgTAP files (`supabase test db`)
|
||||||
# pnpm db:sandbox types [--check] generated types (write, or diff with the committed file)
|
# pnpm db:sandbox types [--check] generated types (write, or diff with the committed file)
|
||||||
# pnpm db:sandbox test packages/supabase/tests/sandbox (HTTP, concurrency)
|
# pnpm db:sandbox test packages/supabase/tests/sandbox (HTTP, concurrency)
|
||||||
@@ -172,14 +174,29 @@ gotrue_accounts() {
|
|||||||
-d '{"email":"pre-unconfirmed@sandbox.local","password":"Sandbox-only-pw-1"}' >/dev/null
|
-d '{"email":"pre-unconfirmed@sandbox.local","password":"Sandbox-only-pw-1"}' >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# A CLI workdir holding only the migrations before <version>; kept in the
|
||||||
|
# state folder and refilled at each run (the CLI writes .temp there).
|
||||||
|
upgrade_workdir() { # version
|
||||||
|
local base="$STATE/upgrade-base"
|
||||||
|
mkdir -p "$base/supabase/migrations"
|
||||||
|
rm -f "$base"/supabase/migrations/*.sql
|
||||||
|
cp supabase/config.toml "$base/supabase/"
|
||||||
|
for f in supabase/migrations/*.sql; do
|
||||||
|
if [ "$(basename "$f" | cut -d_ -f1)" \< "$1" ]; then cp "$f" "$base/supabase/migrations/"; fi
|
||||||
|
done
|
||||||
|
printf '%s' "$base"
|
||||||
|
}
|
||||||
|
|
||||||
cmd_up() {
|
cmd_up() {
|
||||||
local mode="${1:-}"
|
local mode="${1:-}"
|
||||||
# Arguments checked before anything starts: a refusal leaves no container or secret.
|
# Arguments checked before anything starts: a refusal leaves no container or secret.
|
||||||
case "$mode" in
|
case "$mode" in
|
||||||
fresh) ;;
|
fresh) ;;
|
||||||
upgrade) [[ "${2:-}" =~ ^[0-9]{14}$ ]] \
|
upgrade) [[ "${2:-}" =~ ^[0-9]{14}$ ]] \
|
||||||
|| die "up upgrade needs the first new migration version, e.g. 20261025100000" ;;
|
|| die "up upgrade needs the first new migration version, e.g. 20261025100000"
|
||||||
*) die "up fresh | up upgrade <version>" ;;
|
[ -z "${3:-}" ] || { [[ "$3" =~ ^[0-9]{14}$ ]] && [ "$2" \< "$3" ]; } \
|
||||||
|
|| die "up upgrade <version> <then>: <then> is a later migration version" ;;
|
||||||
|
*) die "up fresh | up upgrade <version> [<then>]" ;;
|
||||||
esac
|
esac
|
||||||
docker ps -a --format '{{.Names}}' | grep -q '^faunosteo_dbsandbox_' && die "already up (pnpm db:sandbox down)"
|
docker ps -a --format '{{.Names}}' | grep -q '^faunosteo_dbsandbox_' && die "already up (pnpm db:sandbox down)"
|
||||||
new_secrets
|
new_secrets
|
||||||
@@ -188,19 +205,13 @@ cmd_up() {
|
|||||||
fresh)
|
fresh)
|
||||||
migrate_up . ; seed ;;
|
migrate_up . ; seed ;;
|
||||||
upgrade)
|
upgrade)
|
||||||
local version="$2"
|
migrate_up "$(upgrade_workdir "$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"
|
|
||||||
mkdir -p "$base/supabase/migrations"
|
|
||||||
rm -f "$base"/supabase/migrations/*.sql
|
|
||||||
cp supabase/config.toml "$base/supabase/"
|
|
||||||
for f in supabase/migrations/*.sql; do
|
|
||||||
if [ "$(basename "$f" | cut -d_ -f1)" \< "$version" ]; then cp "$f" "$base/supabase/migrations/"; fi
|
|
||||||
done
|
|
||||||
migrate_up "$base"
|
|
||||||
seed; gotrue_accounts
|
seed; gotrue_accounts
|
||||||
echo "== before: $(sb_psql -t -A -c 'select count(*) from public.profiles') profiles"
|
echo "== before: $(sb_psql -t -A -c 'select count(*) from public.profiles') profiles"
|
||||||
|
if [ -n "${3:-}" ]; then
|
||||||
|
migrate_up "$(upgrade_workdir "$3")"
|
||||||
|
echo "== between: $(sb_psql -t -A -c 'select count(*) from public.workspaces') workspaces"
|
||||||
|
fi
|
||||||
migrate_up . ;;
|
migrate_up . ;;
|
||||||
esac
|
esac
|
||||||
start_rest
|
start_rest
|
||||||
@@ -238,5 +249,5 @@ case "${1:-}" in
|
|||||||
test) load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/supabase test:sandbox ;;
|
test) load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/supabase test:sandbox ;;
|
||||||
e2e-shell) load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/app e2e:shell ;;
|
e2e-shell) load_secrets; with_sandbox_env node_modules/.bin/pnpm --filter @faunosteo/app e2e:shell ;;
|
||||||
sql) load_secrets; sb_psql ;;
|
sql) load_secrets; sb_psql ;;
|
||||||
*) sed -n '2,24p' "$0"; exit 1 ;;
|
*) sed -n '2,23p' "$0"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
Reference in new issue
Block a user