Last active
March 15, 2024 11:21
-
-
Save SevInf/3ce6aae708e12edabcb33967bc11d404 to your computer and use it in GitHub Desktop.
Script for managing prisma engines versions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Instructions | |
| # 1. Download this script | |
| # 2. Add `source /path/to/the/script.sh` to your shell profile | |
| # 3. Reload the shell | |
| # 4. Use the command: | |
| # - `prisma-engine use /path/to/checkout/dir` for local checkout | |
| # - `prisma-engine use 12345` for github pull requests | |
| # - `prisma-engine unuse` for resetting all env variables and switching back | |
| # to default engine | |
| function _prisma-engine() ( | |
| set -euo pipefail | |
| local ROOT_DIR="$HOME/.prisma-engine" | |
| local CHECKOUT_DIR="$ROOT_DIR/checkout" | |
| local CHECKOUT_GIT_DIR="$ROOT_DIR/checkout/.git" | |
| local NODE_API_LIB="$ROOT_DIR/libquery_engine.dylib.node" | |
| local ENGINES_REPO="https://github.com/prisma/prisma-engines.git" | |
| echoerr() { echo "$@" 1>&2; } | |
| print_usage() { | |
| echoerr 'Usage:' | |
| echoerr 'prisma-engine use <path to engine dir>' | |
| echoerr 'prisma-engine use <github pr id>' | |
| echoerr 'prisma-engine unuse' | |
| return 1 | |
| } | |
| checkout_git() { | |
| git --git-dir="$CHECKOUT_GIT_DIR" --work-tree="$CHECKOUT_DIR" $@ 1>&2 | |
| } | |
| use() { | |
| if [ -z "$1" ]; then | |
| print_usage | |
| return $? | |
| fi | |
| local ENDMSG="" | |
| local ENGINE_DIR="" | |
| mkdir -p "$ROOT_DIR" | |
| if [ -d "$1" ]; then | |
| ENGINE_DIR=$(cd $1;pwd) | |
| ENDMSG="Now using engine from $ENGINE_DIR" | |
| else | |
| # if it is not a local path, presume github PR | |
| if ! [ -d "$CHECKOUT_DIR" ]; then | |
| git clone --depth=1 "$ENGINES_REPO" "$CHECKOUT_DIR" | |
| fi | |
| checkout_git fetch --depth=1 origin "pull/$1/head" | |
| checkout_git checkout FETCH_HEAD | |
| ENGINE_DIR="$CHECKOUT_DIR" | |
| ENDMSG="Now using engine from Github PR#$1" | |
| fi | |
| rm -f "$NODE_API_LIB" | |
| cargo build --manifest-path "$ENGINE_DIR/Cargo.toml" --debug \ | |
| --package query-engine-node-api \ | |
| --package query-engine \ | |
| --package schema-engine-cli \ | |
| --package prisma-fmt | |
| cp "$ENGINE_DIR/target/debug/libquery_engine.dylib" "$NODE_API_LIB" | |
| echo "export PRISMA_QUERY_ENGINE_LIBRARY='$NODE_API_LIB'" | |
| echo "export PRISMA_QUERY_ENGINE_BINARY='$ENGINE_DIR/target/debug/query-engine'" | |
| echo "export PRISMA_SCHEMA_ENGINE_BINARY='$ENGINE_DIR/target/debug/schema-engine'" | |
| echoerr "$ENDMSG" | |
| } | |
| unuse() { | |
| echo 'unset PRISMA_QUERY_ENGINE_LIBRARY' | |
| echo 'unset PRISMA_QUERY_ENGINE_BINARY' | |
| echo 'unset PRISMA_SCHEMA_ENGINE_BINARY' | |
| echoerr "Now using default engine" | |
| } | |
| case $1 in | |
| 'use') | |
| shift | |
| use $@ | |
| return $? | |
| ;; | |
| 'unuse') | |
| shift | |
| unuse $@ | |
| return $? | |
| ;; | |
| *) | |
| print_usage | |
| return $? | |
| ;; | |
| esac | |
| ) | |
| function prisma-engine() { | |
| eval $(_prisma-engine $@) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment