Skip to content

Commit

Permalink
Merge pull request #1916 from mringler/fixes_in_setup_script_for_post…
Browse files Browse the repository at this point in the history
…gres_tests

setup postres tests without password prompt
  • Loading branch information
dereuromark authored Nov 20, 2022
2 parents fa19b97 + 3205909 commit 12c23e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ jobs:
if: matrix.db-type == 'pgsql'
run: tests/bin/setup.pgsql.sh
env:
PGPASSWORD: 'postgres'
DB_NAME: 'propel-tests'
DB_USER: 'postgres'
DB_PW: 'postgres'
Expand Down
40 changes: 23 additions & 17 deletions tests/bin/setup.pgsql.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/bin/sh

psql=`which psql`;

if [ "$psql" = "" ]; then
echo "Can not find psql binary. Is it installed?";
if ! command -v psql > /dev/null; then
echo "Cannot find psql binary. Is it installed?";
exit 1;
fi

Expand All @@ -18,23 +16,31 @@ if [ "$DB_NAME" = "" ]; then
fi

DB_HOSTNAME=${DB_HOSTNAME-127.0.0.1};
DB_PW=${DB_PW-$PGPASSWORD};

if [ "$PGPASSWORD" != '' ]; then
if [ -z "$DB_PW" ]; then
echo "\$DB_PW not set. Leaving empty."
else
NO_PWD="--no-password"
fi

"$psql" --version;

dropdb --host="$DB_HOSTNAME" --username="$DB_USER" "$NO_PWD" "$DB_NAME";

createdb --host="$DB_HOSTNAME" --username="$DB_USER" "$NO_PWD" "$DB_NAME";

"$psql" --host="$DB_HOSTNAME" --username="$DB_USER" -c '
CREATE SCHEMA bookstore_schemas;
CREATE SCHEMA contest;
CREATE SCHEMA second_hand_books;
CREATE SCHEMA migration;
' "$DB_NAME";
(
export PGPASSWORD=$DB_PW;

echo "removing existing test db"
dropdb --host="$DB_HOSTNAME" --username="$DB_USER" $NO_PWD "$DB_NAME";

echo "creating new test db"
createdb --host="$DB_HOSTNAME" --username="$DB_USER" $NO_PWD "$DB_NAME";

echo "creating schema"
psql --host="$DB_HOSTNAME" --username="$DB_USER" $NO_PWD -c '
CREATE SCHEMA bookstore_schemas;
CREATE SCHEMA contest;
CREATE SCHEMA second_hand_books;
CREATE SCHEMA migration;
' "$DB_NAME" >/dev/null;
)

DIR=`dirname $0`;
dsn="pgsql:host=$DB_HOSTNAME;dbname=$DB_NAME";
Expand Down

0 comments on commit 12c23e1

Please sign in to comment.