Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions conductor-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -e

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

error() { echo -e "${RED}✗${NC} $1"; exit 1; }
success() { echo -e "${GREEN}✓${NC} $1"; }

echo "🚀 Setting up Superset workspace..."

# Check dependencies
command -v bun &> /dev/null || error "Bun not installed. Install from https://bun.sh"
command -v neonctl &> /dev/null || error "Neon CLI not installed. Run: npm install -g neonctl"
command -v jq &> /dev/null || error "jq not installed. Run: brew install jq"

# Install dependencies
echo "📥 Installing dependencies..."
bun install
success "Dependencies installed"

# Link direnv config
echo "🔧 Linking .envrc..."
ln -sf "$CONDUCTOR_ROOT_PATH/.envrc" .envrc
success "direnv configured"

# Create Neon branch for this workspace
echo "🗄️ Creating Neon branch..."
WORKSPACE_NAME=$(basename "${CONDUCTOR_WORKSPACE_PATH:-$PWD}")
NEON_OUTPUT=$(neonctl branches create \
--project-id tiny-cherry-82420694 \
--name "$WORKSPACE_NAME" \
--output json)
Comment on lines +30 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Script is not idempotent; rerunning will attempt duplicate Neon branch creation.

Neon will reject a second branches create call with the same --name. Running this setup script twice in the same workspace will fail. Consider:

  • Checking if the branch already exists before attempting creation, or
  • Documenting that the script should only run once per workspace, or
  • Providing a separate idempotent "refresh" command if re-initialization is needed.

This could be addressed with a check before branch creation:

 WORKSPACE_NAME=$(basename "${CONDUCTOR_WORKSPACE_PATH:-$PWD}")
+
+# Check if branch already exists
+if neonctl branches get "$WORKSPACE_NAME" --project-id "${NEON_PROJECT_ID}" &> /dev/null; then
+  echo "ℹ️  Neon branch already exists: $WORKSPACE_NAME"
+  NEON_OUTPUT=$(neonctl branches get "$WORKSPACE_NAME" --project-id "${NEON_PROJECT_ID}" --output json)
+else
+  echo "Creating new Neon branch..."
 NEON_OUTPUT=$(neonctl branches create \
-  --project-id tiny-cherry-82420694 \
+  --project-id "${NEON_PROJECT_ID:?Error: NEON_PROJECT_ID not set}" \
   --name "$WORKSPACE_NAME" \
   --output json)
+fi

Verify that neonctl branches get and neonctl branches create outputs are compatible with the downstream JSON parsing.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
WORKSPACE_NAME=$(basename "${CONDUCTOR_WORKSPACE_PATH:-$PWD}")
NEON_OUTPUT=$(neonctl branches create \
--project-id tiny-cherry-82420694 \
--name "$WORKSPACE_NAME" \
--output json)
WORKSPACE_NAME=$(basename "${CONDUCTOR_WORKSPACE_PATH:-$PWD}")
# Check if branch already exists
if neonctl branches get "$WORKSPACE_NAME" --project-id "${NEON_PROJECT_ID}" &> /dev/null; then
echo "ℹ️ Neon branch already exists: $WORKSPACE_NAME"
NEON_OUTPUT=$(neonctl branches get "$WORKSPACE_NAME" --project-id "${NEON_PROJECT_ID}" --output json)
else
echo "Creating new Neon branch..."
NEON_OUTPUT=$(neonctl branches create \
--project-id "${NEON_PROJECT_ID:?Error: NEON_PROJECT_ID not set}" \
--name "$WORKSPACE_NAME" \
--output json)
fi
🤖 Prompt for AI Agents
In conductor-setup.sh around lines 16 to 20, the script always calls `neonctl
branches create` which is not idempotent and will fail on reruns; change it to
first check for an existing branch by name (e.g., use `neonctl branches get` or
`neonctl branches list`/filter) and reuse the existing branch output if found,
otherwise call `neonctl branches create`; ensure you handle and parse both `get`
and `create` JSON outputs consistently (extract the branch identifier/URL the
rest of the script expects) and surface any errors clearly so the script can be
safely re-run.

Comment on lines +32 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Remove hardcoded project-id from the script.

Embedding tiny-cherry-82420694 as a hardcoded string violates configuration management best practices and creates a security risk by exposing project identifiers in version control. This should be sourced from an environment variable or configuration file instead.

Apply this diff to externalize the project-id:

 WORKSPACE_NAME=$(basename "${CONDUCTOR_WORKSPACE_PATH:-$PWD}")
-NEON_OUTPUT=$(neonctl branches create \
-  --project-id tiny-cherry-82420694 \
+NEON_OUTPUT=$(neonctl branches create \
+  --project-id "${NEON_PROJECT_ID:?Error: NEON_PROJECT_ID not set}" \
   --name "$WORKSPACE_NAME" \
   --output json)

Ensure NEON_PROJECT_ID is set via environment variable, .env, or passed by the conductor framework before invoking this script.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
--project-id tiny-cherry-82420694 \
--name "$WORKSPACE_NAME" \
--output json)
--project-id "${NEON_PROJECT_ID:?Error: NEON_PROJECT_ID not set}" \
--name "$WORKSPACE_NAME" \
--output json)
🤖 Prompt for AI Agents
In conductor-setup.sh around lines 18 to 20, the script currently hardcodes the
project-id "tiny-cherry-82420694"; replace that literal with an
environment-driven value (e.g., use $NEON_PROJECT_ID), ensure the script
validates that NEON_PROJECT_ID is set (exit with a clear error if missing), and
document or load it from .env or the calling environment so the project id is
not embedded in source control.


# Parse connection strings and create .env
DATABASE_URL=$(echo "$NEON_OUTPUT" | jq -r '.connection_uris[0].connection_uri')
DATABASE_POOLED_URL=$(echo "$NEON_OUTPUT" | jq -r '.connection_uris[1].connection_uri // empty')
Comment on lines +37 to +38

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fragile JSON parsing; assume specific Neon API response structure without graceful degradation.

The jq filters assume connection_uris[0] and connection_uris[1] always exist. If the Neon API response structure differs (e.g., fewer URIs, different keys, or schema changes), parsing will silently fail or produce null. The // empty fallback for DATABASE_POOLED_URL is good, but DATABASE_URL has no fallback and will be set to "null" string if missing, which will corrupt the .env file.

Strengthen the parsing logic and add validation (see previous comment for a full fix). Additionally, verify the jq output:

# Debug: Print the Neon output structure before parsing
echo "$NEON_OUTPUT" | jq '.'

Confirm that .connection_uris[0].connection_uri and .connection_uris[1].connection_uri are the correct paths in all cases.

🤖 Prompt for AI Agents
In conductor-setup.sh around lines 23 to 24, the jq parsing assumes
connection_uris[0] always exists and will write the string "null" into the .env
if missing; change the parsing to (1) print/debug the raw NEON_OUTPUT (echo
"$NEON_OUTPUT" | jq '.') before extraction, (2) use jq with safe fallbacks for
DATABASE_URL and DATABASE_POOLED_URL (e.g. fall back to empty string or
alternate keys) so neither becomes the literal "null", (3) validate after
extraction that DATABASE_URL is non-empty and exit with a clear error if it is
missing, and (4) add a brief comment verifying the expected JSON paths and
handling alternate shapes so the script degrades gracefully when URIs are
absent.


cat > .env << EOF
DATABASE_URL=$DATABASE_URL
DATABASE_POOLED_URL=$DATABASE_POOLED_URL
EOF
Comment on lines +40 to +43

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

.env file is overwritten without warning, backup, or existence check.

If a user has manually edited or created a .env file with custom values, running this script will silently overwrite it. Consider:

  • Checking if .env already exists and prompting the user, or
  • Creating a backup before overwriting, or
  • Generating a workspace-specific .env.conductor and sourcing it if needed.

Apply this diff to add a safety check:

-cat > .env << EOF
+if [[ -f .env ]]; then
+  echo "⚠️  Warning: .env already exists. Backing up to .env.bak"
+  mv .env .env.bak
+fi
+
+cat > .env << EOF
 DATABASE_URL=$DATABASE_URL
 DATABASE_POOLED_URL=$DATABASE_POOLED_URL
 EOF
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cat > .env << EOF
DATABASE_URL=$DATABASE_URL
DATABASE_POOLED_URL=$DATABASE_POOLED_URL
EOF
if [[ -f .env ]]; then
echo "⚠️ Warning: .env already exists. Backing up to .env.bak"
mv .env .env.bak
fi
cat > .env << EOF
DATABASE_URL=$DATABASE_URL
DATABASE_POOLED_URL=$DATABASE_POOLED_URL
EOF
🤖 Prompt for AI Agents
In conductor-setup.sh around lines 26 to 29, the script blindly writes a .env
file which can overwrite a user's existing file; modify the script to first
check for an existing .env and if found either prompt the user to confirm
overwrite, create a timestamped backup (e.g., .env.bak.YYYYMMDD_HHMMSS), or
write to a workspace-specific file like .env.conductor and optionally source it;
implement one of these flows and ensure the script communicates the action to
the user (prompt/backup created/alternate file written) before proceeding.


success "Neon branch created: $WORKSPACE_NAME"
echo "✨ Done!"
5 changes: 5 additions & 0 deletions conductor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"scripts": {
"setup": "./conductor-setup.sh"
}
}
Loading