refactor(dev): share postgres across main and worktrees

This commit is contained in:
Jiayuan Zhang 2026-03-24 14:27:35 +08:00
parent 94c9b07bfb
commit 2c28c4cba2
16 changed files with 839 additions and 359 deletions

View file

@ -17,15 +17,13 @@ fi
hash_value="$(printf '%s' "$PWD" | cksum | awk '{print $1}')"
offset=$((hash_value % 1000))
postgres_db="multica_${slug}"
postgres_port=$((15432 + offset))
postgres_db="multica_${slug}_${offset}"
postgres_port=5432
backend_port=$((18080 + offset))
frontend_port=$((13000 + offset))
frontend_origin="http://localhost:${frontend_port}"
compose_project_name="multica_${slug}_${offset}"
cat > "$ENV_FILE" <<EOF
COMPOSE_PROJECT_NAME=${compose_project_name}
POSTGRES_DB=${postgres_db}
POSTGRES_USER=multica
POSTGRES_PASSWORD=multica
@ -47,10 +45,11 @@ NEXT_PUBLIC_WS_URL=ws://localhost:${backend_port}/ws
EOF
echo "Generated $ENV_FILE for worktree '$worktree_name'"
echo " Postgres: ${postgres_db} on localhost:${postgres_port}"
echo " Shared Postgres: localhost:${postgres_port}"
echo " Database: ${postgres_db}"
echo " Backend: http://localhost:${backend_port}"
echo " Frontend: ${frontend_origin}"
echo ""
echo "Next steps:"
echo " make setup"
echo " make start"
echo " make setup-worktree"
echo " make start-worktree"