diff --git a/scripts/worktree-cleanup b/scripts/worktree-cleanup index 078d3882e6..c9a2769a58 100755 --- a/scripts/worktree-cleanup +++ b/scripts/worktree-cleanup @@ -23,6 +23,20 @@ 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") diff --git a/scripts/worktree-env b/scripts/worktree-env index 5edacccf20..0c3c56dea3 100755 --- a/scripts/worktree-env +++ b/scripts/worktree-env @@ -52,6 +52,34 @@ fi echo "Created .env.local with ports: backend=$backend_port, frontend=$frontend_port" +# --- Create per-worktree database --- +wt_basename=$(basename "$(pwd)") +db_name="windmill_${wt_basename//-/_}" +db_conn="postgres://postgres:changeme@127.0.0.1:5432" + +if command -v psql &>/dev/null; then + if psql "$db_conn/postgres" -tc "SELECT 1 FROM pg_database WHERE datname = '${db_name}'" 2>/dev/null | grep -q 1; then + echo "Database $db_name already exists" + else + psql "$db_conn/postgres" -c "CREATE DATABASE ${db_name}" 2>/dev/null \ + && echo "Created database $db_name" \ + || echo "WARNING: Could not create database $db_name (is PostgreSQL running?)" >&2 + fi + db_url="${db_conn}/${db_name}?sslmode=disable" + # Run migrations against the new database + DATABASE_URL="$db_url" sqlx migrate run --source backend/migrations \ + && echo "Migrations applied to $db_name" \ + || echo "WARNING: Could not run migrations on $db_name" >&2 + # Use export so DATABASE_URL overrides the nix devshell value for child processes + cat >> .env.local <&2 +fi + # --- Copy frontend/node_modules preserving symlinks --- # cp -a preserves .bin/ symlinks that cp -r would dereference, breaking require() paths main_repo_root="$(cd "$(git rev-parse --git-common-dir 2>/dev/null)/.." && pwd)" @@ -66,6 +94,25 @@ if command -v direnv &>/dev/null && [ -f .envrc ]; then echo "direnv allowed" fi +# --- Trust worktree directory in Claude Code --- +claude_json="$HOME/.claude.json" +if [ -f "$claude_json" ]; then + wt_path="$(pwd)" + python3 -c " +import json, sys +path = '$wt_path' +with open('$claude_json', 'r') as f: + data = json.load(f) +projects = data.setdefault('projects', {}) +proj = projects.setdefault(path, {}) +proj['hasTrustDialogAccepted'] = True +proj['hasCompletedProjectOnboarding'] = True +with open('$claude_json', 'w') as f: + json.dump(data, f, indent=2) +" && echo "Added $wt_path to Claude Code trusted directories" \ + || echo "Warning: Could not update Claude Code trusted directories" +fi + # --- Create matching windmill-ee-private worktree --- # Find ee repo: sibling to the main worktree (git toplevel of the main checkout), # then try parent of cwd, then fall back to home