diff --git a/driver-adapters-wasm/pg-cf-hyperdrive/prepare.sh b/driver-adapters-wasm/pg-cf-hyperdrive/prepare.sh index 4e316ca7fc39..3229b251fe99 100755 --- a/driver-adapters-wasm/pg-cf-hyperdrive/prepare.sh +++ b/driver-adapters-wasm/pg-cf-hyperdrive/prepare.sh @@ -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`: # @@ -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`: @@ -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 < wrangler.toml name = "pg-cf-hyperdrive" @@ -64,4 +79,4 @@ EOF echo "✅ Configured wrangler.toml with hyperdrive id $HYPERDRIVE_ID" echo "" -cat wrangler.toml \ No newline at end of file +cat wrangler.toml