Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(pg-cf-hyperdrive): improve delete hyperdrive script #4915

Merged
merged 9 commits into from
May 7, 2024
Merged
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
27 changes: 21 additions & 6 deletions driver-adapters-wasm/pg-cf-hyperdrive/prepare.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env bash

set -eux

export TMP_FILE=hyperdrive.tmp
export PRISMA_TELEMETRY_INFORMATION='ecosystem-tests driver-adapters-wasm pg-cf-hyperdrive build'
export PRISMA_CLIENT_ENGINE_TYPE='wasm' # because setup otherwise makes it library/binary
export HYPERDRIVE_NAME='hyperdrive-pg-cf-hyperdrive'

# Delete a previous hyperdrive with the same name if exists, unfortunately wrangler output cannot
# be parsed as JSON, so we need to filter out the id from the output table. We do it in two steps
# to count with debugging output
# be parsed as JSON, so we need to filter out the id from the output table. We do it in two steps
# to count with debugging output
#
# Example output of `wrangler hyperdrive list`:
#
Expand All @@ -24,9 +26,15 @@ export HYPERDRIVE_NAME='hyperdrive-pg-cf-hyperdrive'
# └──────────────────────────────────┴─────────────────────────────┴──────────────────────┴───────────────────────────────────────────────────────────────────────┴──────┴────────────────┴────────────────────┘
# ```
npx wrangler hyperdrive list | tee $TMP_FILE
cat $TMP_FILE | grep $HYPERDRIVE_NAME |cut -f2 -d' ' |xargs npx wrangler hyperdrive delete
# Only try to delete if the hyperdrive exists
if [ $(grep -c $HYPERDRIVE_NAME $TMP_FILE) = 0 ]; then
echo "✅ No existing hyperdrive with name $HYPERDRIVE_NAME - We can continue..."
else
echo "Existing hyperdrive with name $HYPERDRIVE_NAME - We will delete it..."
grep $HYPERDRIVE_NAME $TMP_FILE | cut -f2 -d' ' | xargs npx wrangler hyperdrive delete
fi

# Create the hyperdrive to connecto the Database. Unfortunately wrangler output mixes JSON and text, so we need to filter out
# Create the hyperdrive to connecto the Database. Unfortunately wrangler output mixes JSON and text, so we need to filter out
# the first two lines to parse the JSON.
#
# Example output of `wrangler hyperdrive create hyperdrive-orm-tests-foo --connection-string=$DATABASE_URL`:
Expand All @@ -48,8 +56,15 @@ cat $TMP_FILE | grep $HYPERDRIVE_NAME |cut -f2 -d' ' |xargs npx wrangler hyperdr
# }
# }
# ```

# if DATABASE_URL is not set, exit
if [ -z "$DATABASE_URL" ]; then
echo "DATABASE_URL is not set"
exit 1
fi

npx wrangler hyperdrive create $HYPERDRIVE_NAME --connection-string=\"$DATABASE_URL\" | tee $TMP_FILE
export HYPERDRIVE_ID=$(cat $TMP_FILE |sed 1,2d | jq .id)
export HYPERDRIVE_ID=$(cat $TMP_FILE | sed 1,2d | jq .id)

cat <<EOF > wrangler.toml
name = "pg-cf-hyperdrive"
Expand All @@ -64,4 +79,4 @@ EOF

echo "✅ Configured wrangler.toml with hyperdrive id $HYPERDRIVE_ID"
echo ""
cat wrangler.toml
cat wrangler.toml