From 32188648762c6566de1686a044a0239062a5d990 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 17 Mar 2019 03:52:56 +0100 Subject: [PATCH] Fix ynh_psql_execute_as_root --- scripts/remove | 3 ++- scripts/restore | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/remove b/scripts/remove index e465098..50479bb 100755 --- a/scripts/remove +++ b/scripts/remove @@ -55,7 +55,8 @@ ynh_remove_systemd_config #================================================= ynh_print_info "Removing the PostgreSQL database" -ynh_psql_execute_as_root "SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';" +ynh_psql_execute_as_root "\connect $db_name +SELECT pg_terminate_backend (pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '$db_name';" # Remove a database if it exists, along with the associated user ynh_psql_remove_db "$db_name" "$db_name" diff --git a/scripts/restore b/scripts/restore index 1a7a0ab..8116c0c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -118,10 +118,15 @@ ynh_print_info "Restoring the PostgreSQL database..." ynh_psql_test_if_first_run ynh_psql_create_user "$app" "$db_pwd" -ynh_psql_execute_as_root "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $app;" -ynh_psql_execute_as_root "CREATE EXTENSION IF NOT EXISTS citext;" -ynh_psql_execute_as_root "CREATE EXTENSION IF NOT EXISTS pg_trgm;" -ynh_psql_execute_as_root "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" +ynh_psql_execute_as_root "CREATE DATABASE $db_name ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER $db_name;" +ynh_psql_execute_as_root "\connect $db_name +CREATE EXTENSION IF NOT EXISTS unaccent;" +ynh_psql_execute_as_root "\connect $db_name +CREATE EXTENSION IF NOT EXISTS pg_trgm;" +ynh_psql_execute_as_root "\connect $db_name +CREATE EXTENSION IF NOT EXISTS citext;" +ynh_psql_execute_as_root "\connect $db_name +CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" ynh_psql_execute_file_as_root ./db.sql "$db_name" #=================================================