From 6d9fcfa09fd000fa79d46fe69d30cbba2e2575a6 Mon Sep 17 00:00:00 2001 From: monacoremo <59358383+monacoremo@users.noreply.github.com> Date: Fri, 6 Aug 2021 18:09:09 +0200 Subject: [PATCH] ci: Remove unused create_test_db script --- nix/tools/style.nix | 2 +- test/create_test_db | 71 --------------------------------------------- 2 files changed, 1 insertion(+), 72 deletions(-) delete mode 100755 test/create_test_db diff --git a/nix/tools/style.nix b/nix/tools/style.nix index ed354d969..a791f2d01 100644 --- a/nix/tools/style.nix +++ b/nix/tools/style.nix @@ -57,7 +57,7 @@ let | xargs ${hlint}/bin/hlint -X QuasiQuotes -X NoPatternSynonyms # Lint bash scripts - ${shellcheck}/bin/shellcheck test/create_test_db test/memory-tests.sh + ${shellcheck}/bin/shellcheck test/with_tmp_db ''; in diff --git a/test/create_test_db b/test/create_test_db deleted file mode 100755 index 3a90893a9..000000000 --- a/test/create_test_db +++ /dev/null @@ -1,71 +0,0 @@ -#! /usr/bin/env bash - -usage() { - echo "$0 " - exit 1 -} - -if [ -z "$1" ]; then - echo "Please supply the connection uri for the user with create database privileges" - usage -fi - -if [ -z "$2" ]; then - echo "Please supply the test database name" - usage -fi - -if [[ $1 != postgres://* ]]; then - echo "Please use a valid connection URI (https://www.postgresql.org/docs/current/static/libpq-connect.html#AEN45347)" - usage -fi - -BASEPATH=$( cd "$(dirname "$0")" && pwd -P ) -URI="$1" -#Extract host and port--we need this to form the new connection string -HOST_PORT=$(echo "$URI" | cut -d'/' -f3 | cut -d'@' -f2 ) -DB=$2 -# Specify the username of choice, or let the script create a random unique user by appending the database name -TEST_USER_NAME=postgrest_test_authenticator -# New password will get assigned only if the user does not already exist -# Otherwise make sure to provide the correct password for the existing user -TEST_USER_PASS=$(< /dev/urandom env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) - -if ! PGOPTIONS='-c client_min_messages=WARNING' psql "$URI" -Xq >/dev/null -c 'select rolcreatedb from pg_authid where rolname = current_user;' 2>/dev/null; -then - echo "ERROR: Please specify the user with 'Create DB' permissions, and ensure that the default database for the username exists." - exit 1 -fi - -# plpgsql does not like psql variables, easier to pull this part off with bash variables -PGOPTIONS='-c client_min_messages=WARNING' psql "$URI" -Xq >/dev/null < pg_backend_pid(); - -DROP DATABASE IF EXISTS $DB; -DROP ROLE IF EXISTS $TEST_USER_NAME; -CREATE USER $TEST_USER_NAME WITH SUPERUSER LOGIN NOINHERIT PASSWORD '$TEST_USER_PASS' CREATEROLE; -ALTER ROLE postgrest_test_authenticator SET default_text_search_config TO english; -CREATE DATABASE $DB OWNER $TEST_USER_NAME LC_COLLATE 'POSIX' LC_CTYPE 'POSIX' TEMPLATE template0; -\\connect $DB -ALTER SCHEMA public OWNER TO $TEST_USER_NAME; -ALTER DATABASE $DB SET LC_MESSAGES = 'POSIX'; -ALTER DATABASE $DB SET LC_MONETARY = 'POSIX'; -ALTER DATABASE $DB SET LC_NUMERIC = 'POSIX'; -ALTER DATABASE $DB SET LC_TIME = 'POSIX'; - -\i $BASEPATH/fixtures/load.sql -EOF - -#Remove database path from the connection uri--prevents setting up the new database name with PGDATABASE -URI=$(echo "$URI" | cut -d'/' -f1-3) - -# Create a new connection string to use with the test runner -export PGRST_DB_URI="postgres://${TEST_USER_NAME}:$TEST_USER_PASS@$HOST_PORT/$DB" -export PGRST_DB_ANON_ROLE="postgrest_test_anonymous" -export PGRST_DB_SCHEMAS="test" - -shift 2 -"$@"