Skip to content

Commit

Permalink
Better error message when psql is not there for database_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
autra committed May 16, 2020
1 parent ba709be commit bd9feb7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion data/helpers.d/postgresql
Expand Up @@ -187,7 +187,12 @@ ynh_psql_database_exists() {
# Manage arguments with getopts
ynh_handle_getopts_args "$@"

if ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database"
# if postgres user doesn't exist, we consider the db does not as well
# (though strictly speaking it could in an old cluster)
if ! command -v psql
then
ynh_die --message="PostgreSQL is not installed, impossible to check for db existence"
elif ! sudo --login --user=postgres PGUSER="postgres" PGPASSWORD="$(cat $PSQL_ROOT_PWD_FILE)" psql -tAc "SELECT datname FROM pg_database WHERE datname='$database';" | grep --quiet "$database"
then
return 1
else
Expand Down

0 comments on commit bd9feb7

Please sign in to comment.