mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-18 16:02:10 +00:00
09970cd22b
Create a dedicated PostgreSQL database for each worktree during workmux post_create, run sqlx migrations, and drop it on cleanup. Also auto-trust the worktree directory in ~/.claude.json. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
74 lines
2.9 KiB
Bash
Executable File
74 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Use WM_WORKTREE_PATH (set by workmux) so this works regardless of cwd
|
|
wt_dir="${WM_WORKTREE_PATH:-.}"
|
|
echo "[cleanup] cwd=$(pwd) WM_WORKTREE_PATH=${WM_WORKTREE_PATH:-<unset>} wt_dir=$wt_dir"
|
|
|
|
# Kill backend/frontend processes using this worktree's ports
|
|
if [ -f "$wt_dir/.env.local" ]; then
|
|
source "$wt_dir/.env.local"
|
|
echo "[cleanup] .env.local found: BACKEND_PORT=${BACKEND_PORT:-<unset>} FRONTEND_PORT=${FRONTEND_PORT:-<unset>}"
|
|
for port in "${BACKEND_PORT:-}" "${FRONTEND_PORT:-}"; do
|
|
[ -z "$port" ] && continue
|
|
pid=$(lsof -ti "TCP:${port}" -sTCP:LISTEN 2>/dev/null || true)
|
|
if [ -n "$pid" ]; then
|
|
kill "$pid" 2>/dev/null && echo "[cleanup] Killed process $pid on port $port" \
|
|
|| echo "[cleanup] Warning: Could not kill process $pid on port $port"
|
|
else
|
|
echo "[cleanup] No process listening on port $port"
|
|
fi
|
|
done
|
|
else
|
|
echo "[cleanup] No .env.local at $wt_dir/.env.local"
|
|
fi
|
|
|
|
# Drop per-worktree database
|
|
if [ -n "${WM_DB_NAME:-}" ]; then
|
|
db_conn="postgres://postgres:changeme@127.0.0.1:5432"
|
|
if command -v psql &>/dev/null; then
|
|
psql "$db_conn/postgres" -c "DROP DATABASE IF EXISTS ${WM_DB_NAME} WITH (FORCE)" 2>/dev/null \
|
|
&& echo "[cleanup] Dropped database $WM_DB_NAME" \
|
|
|| echo "[cleanup] Warning: Could not drop database $WM_DB_NAME"
|
|
else
|
|
echo "[cleanup] psql not found, skipping database cleanup for $WM_DB_NAME"
|
|
fi
|
|
else
|
|
echo "[cleanup] No WM_DB_NAME in .env.local, skipping database cleanup"
|
|
fi
|
|
|
|
# Remove the matching windmill-ee-private worktree if one exists
|
|
wt_basename=$(basename "$wt_dir")
|
|
|
|
# Find ee repo using same discovery logic as worktree-env
|
|
main_repo_root="$(cd "$(git -C "$wt_dir" rev-parse --git-common-dir 2>/dev/null)/.." && pwd)"
|
|
parent_dir="$(cd "$wt_dir/.." && pwd)"
|
|
echo "[cleanup] wt_basename=$wt_basename main_repo_root=$main_repo_root parent_dir=$parent_dir"
|
|
|
|
ee_repo=""
|
|
for candidate in \
|
|
"${main_repo_root:+${main_repo_root}/../windmill-ee-private}" \
|
|
"${parent_dir}/windmill-ee-private" \
|
|
"${HOME}/windmill-ee-private" \
|
|
"${HOME}/projects/windmill-ee-private"; do
|
|
if [ -n "$candidate" ] && [ -d "$candidate" ]; then
|
|
ee_repo="$(cd "$candidate" && pwd)"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$ee_repo" ]; then
|
|
echo "[cleanup] Could not find windmill-ee-private repo, skipping EE worktree cleanup"
|
|
fi
|
|
|
|
ee_worktree_dir="${ee_repo:+${ee_repo}__worktrees/${wt_basename}}"
|
|
echo "[cleanup] ee_repo=${ee_repo:-<not found>} ee_worktree_dir=${ee_worktree_dir:-<none>} exists=$([ -n "$ee_worktree_dir" ] && [ -d "$ee_worktree_dir" ] && echo yes || echo no)"
|
|
if [ -n "$ee_worktree_dir" ] && [ -d "$ee_worktree_dir" ]; then
|
|
git -C "$ee_repo" worktree remove "$ee_worktree_dir" --force 2>/dev/null \
|
|
&& echo "[cleanup] Removed EE worktree at $ee_worktree_dir" \
|
|
|| echo "[cleanup] Warning: Could not remove EE worktree at $ee_worktree_dir"
|
|
fi
|
|
|
|
# Clean up Cursor grouped tmux session
|
|
tmux kill-session -t "cursor-${wt_basename}" 2>/dev/null || true
|