From 660b442943c81c0b352615285f72917bd7e9189f Mon Sep 17 00:00:00 2001 From: Abby Sassel <3883855+sassela@users.noreply.github.com> Date: Wed, 10 Mar 2021 22:18:16 +0000 Subject: [PATCH] server: misc. dev.sh improvements Co-authored-by: Antoine Leblanc <1618949+nicuveo@users.noreply.github.com> GitOrigin-RevId: 4c93b49a370afb98747aabc1c977494297432402 --- scripts/dev.sh | 43 +++++++++++-------- .../src-lib/Hasura/RQL/DDL/Schema/Source.hs | 2 +- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/scripts/dev.sh b/scripts/dev.sh index da096a9ab00..c0d038cec7e 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -159,18 +159,21 @@ fi # export for psql, etc. export PGPASSWORD=postgres # needs at least 8 characters, and lowercase, uppercase and number -export MSSQLPASSWORD="hasuraMSSQL1" +export MSSQL_PASSWORD=hasuraMSSQL1 # The URL for the postgres server we might launch POSTGRES_DB_URL="postgres://postgres:$PGPASSWORD@127.0.0.1:$PG_PORT/postgres" # ... but we might like to use a different PG instance when just launching graphql-engine: HASURA_GRAPHQL_DATABASE_URL=${HASURA_GRAPHQL_DATABASE_URL-$POSTGRES_DB_URL} +# MSSQL connection string as an optional alternative source +MSSQL_DB_URL="DRIVER={ODBC Driver 17 for SQL Server};SERVER=127.0.0.1,$MSSQL_PORT;Uid=sa;Pwd=$MSSQL_PASSWORD;" PG_CONTAINER_NAME="hasura-dev-postgres-$PG_PORT" MSSQL_CONTAINER_NAME="hasura-dev-mssql-$MSSQL_PORT" # We can remove psql as a dependency by using it from the (running) PG container: DOCKER_PSQL="docker exec -u postgres -it $PG_CONTAINER_NAME psql $HASURA_GRAPHQL_DATABASE_URL" +DOCKER_MSSQL="docker exec -it $MSSQL_CONTAINER_NAME /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $MSSQL_PASSWORD" function wait_postgres { echo -n "Waiting for postgres to come up" @@ -180,14 +183,11 @@ function wait_postgres { echo " Ok" } -DOCKER_MSSQL="docker exec -t $MSSQL_CONTAINER_NAME /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $MSSQLPASSWORD" - function wait_mssql { set +e echo -n "Waiting for mssql to come up" $DOCKER_MSSQL -Q "SELECT 1" &>/dev/null - while [ $? -eq 0 ]; - do + while [ $? -ne 0 ]; do echo -n '.' && sleep 0.2 $DOCKER_MSSQL -Q "SELECT 1" &>/dev/null done @@ -331,6 +331,17 @@ EOF # log lines above as -c flag arguments we pass to postgres CONF_FLAGS=$(echo "$CONF" | sed -e 's/^/-c /' | tr '\n' ' ') +function cleanup_postgres(){ + # Since scripts here are tailored to the env we've just launched: + rm -r "$DEV_SHIM_PATH" + + echo_pretty "Removing $PG_CONTAINER_NAME and its volumes in 5 seconds!" + echo_pretty " PRESS CTRL-C TO ABORT removal, or ENTER to clean up right away" + read -t5 || true + docker stop "$PG_CONTAINER_NAME" + docker rm -v "$PG_CONTAINER_NAME" +} + function launch_postgres_container(){ echo_pretty "Launching postgres container: $PG_CONTAINER_NAME" docker run --name "$PG_CONTAINER_NAME" -p 127.0.0.1:"$PG_PORT":$PG_PORT --expose="$PG_PORT" \ @@ -366,14 +377,7 @@ EOL case "$MODE" in test|postgres) - # Since scripts here are tailored to the env we've just launched: - rm -r "$DEV_SHIM_PATH" - - echo_pretty "Removing $PG_CONTAINER_NAME and its volumes in 5 seconds!" - echo_pretty " PRESS CTRL-C TO ABORT removal, or ENTER to clean up right away" - read -t5 || true - docker stop "$PG_CONTAINER_NAME" - docker rm -v "$PG_CONTAINER_NAME" + cleanup_postgres ;; graphql-engine) ;; @@ -411,10 +415,11 @@ fi function launch_mssql_container(){ echo_pretty "Launching MSSQL container: $MSSQL_CONTAINER_NAME" - docker run --name "$MSSQL_CONTAINER_NAME" --net=host \ - -e SA_PASSWORD="$MSSQLPASSWORD" -e "ACCEPT_EULA=Y" -d mcr.microsoft.com/mssql/server:2019-CU8-ubuntu-16.04 + docker run --rm --name $MSSQL_CONTAINER_NAME --net=host \ + -e 'ACCEPT_EULA=Y' -e "SA_PASSWORD=$MSSQL_PASSWORD" \ + -p 127.0.0.1:"$MSSQL_PORT":1433 -d mcr.microsoft.com/mssql/server:2019-CU8-ubuntu-16.04 - # Since launching the postgres container worked we can set up cleanup routines. This will catch CTRL-C + # Since launching the SQL Server container worked we can set up cleanup routines. This will catch CTRL-C function cleanup { echo @@ -429,7 +434,7 @@ function launch_mssql_container(){ echo_pretty " PRESS CTRL-C TO ABORT removal, or ENTER to clean up right away" read -t5 || true docker stop "$MSSQL_CONTAINER_NAME" - docker rm -v "$MSSQL_CONTAINER_NAME" + # container will be removed automatically as it was started using the --rm option ;; graphql-engine) ;; @@ -452,6 +457,10 @@ if [ "$MODE" = "mssql" ]; then echo_pretty "" echo_pretty "If you want to import a SQL file into MSSQL:" echo_pretty " $ $DOCKER_MSSQL -i " + echo_pretty "" + echo_pretty "Here is the database URL:" + echo_pretty " $MSSQL_DB_URL" + echo_pretty "" # Runs continuously until CTRL-C, jumping to cleanup() above: docker logs -f --tail=0 "$MSSQL_CONTAINER_NAME" diff --git a/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs b/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs index 6839cfc394e..8923f65d8b4 100644 --- a/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs +++ b/server/src-lib/Hasura/RQL/DDL/Schema/Source.hs @@ -39,7 +39,7 @@ runAddSource runAddSource (AddSource name sourceConfig) = do sources <- scSources <$> askSchemaCache onJust (HM.lookup name sources) $ const $ - throw400 AlreadyExists $ "postgres source with name " <> name <<> " already exists" + throw400 AlreadyExists $ "source with name " <> name <<> " already exists" buildSchemaCacheFor (MOSource name) $ MetadataModifier $ metaSources %~ OMap.insert name (mkSourceMetadata @b name sourceConfig)