From ae61e6f3d25df98f4ebeca9695a3c73239ce82b2 Mon Sep 17 00:00:00 2001 From: Anton Merzlyakov Date: Wed, 30 Nov 2016 14:29:18 +0300 Subject: [PATCH] Postgres: fix detection of existing roles Role "root" it is hardcode. In general case role name comes from local.conf: string "DATABASE_USER=" Change-Id: Iedfca48e04d23c313851f48d68ac40ba29340805 --- lib/databases/postgresql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/databases/postgresql b/lib/databases/postgresql index 14425a53b7..1f347f5548 100644 --- a/lib/databases/postgresql +++ b/lib/databases/postgresql @@ -47,7 +47,7 @@ function recreate_database_postgresql { } function configure_database_postgresql { - local pg_conf pg_dir pg_hba root_roles version + local pg_conf pg_dir pg_hba check_role version echo_summary "Configuring and starting PostgreSQL" if is_fedora; then pg_hba=/var/lib/pgsql/data/pg_hba.conf @@ -85,8 +85,8 @@ function configure_database_postgresql { restart_service postgresql # Create the role if it's not here or else alter it. - root_roles=$(sudo -u root sudo -u postgres -i psql -t -c "SELECT 'HERE' from pg_roles where rolname='root'") - if [[ ${root_roles} == *HERE ]];then + check_role=$(sudo -u root sudo -u postgres -i psql -t -c "SELECT 'HERE' from pg_roles where rolname='$DATABASE_USER'") + if [[ ${check_role} == *HERE ]];then sudo -u root sudo -u postgres -i psql -c "ALTER ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'" else sudo -u root sudo -u postgres -i psql -c "CREATE ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"