Skip to content

Commit

Permalink
test(pg-cf-hyperdrive): improve delete hyperdrive script (#4915)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 authored May 7, 2024
1 parent 4f35d22 commit f13b1f4
Showing 1 changed file with 21 additions and 6 deletions.
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

0 comments on commit f13b1f4

Please sign in to comment.