Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

1006 B
Raw Blame
#!/usr/bin/env bash
# Drop a worktree's databases. Runs from the worktrunk post-remove hook (in the
# primary checkout, with the removed branch passed as $1) or by hand.
set -euo pipefail
WT_BRANCH="${1:-}"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.sh"

# Refuse to drop databases still claimed by a checked-out worktree — teardown
# normally runs after the worktree is gone, so a live one means we were pointed
# at the wrong branch.
# -F matters: branch names may contain regex metacharacters, and a stray match
# here would refuse a legitimate cleanup.
if git worktree list --porcelain | grep -qxF "branch refs/heads/$(branch_name)"; then
  echo "Branch '$(branch_name)' is still checked out in a worktree — refusing to drop its databases." >&2
  echo "Remove the worktree first (wt remove), or drop them by hand if that is really what you want." >&2
  exit 1
fi

for db in "$(db_name)" "$(test_db_name)"; do
  echo "▸ Dropping $db"
  dropdb "${PG_ARGS[@]}" --if-exists "$db"
done