mirror of
https://github.com/YunoHost-Apps/noalyss_ynh.git
synced 2024-09-03 19:46:20 +02:00
Modified the function removing PostgreSQL databases in the 'remove' script to take into account that this app creates several databases by default and not a unique one
This commit is contained in:
parent
bb681b27c9
commit
b1fac10517
1 changed files with 27 additions and 4 deletions
|
@ -22,12 +22,35 @@ db_user=$db_name
|
||||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE THE POSTGRESQL DATABASE
|
# REMOVE THE POSTGRESQL DATABASE(S) & ROLE
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Removing the PostgreSQL database"
|
ynh_script_progression --message="Removing all associated PostgreSQL database(s) and role"
|
||||||
|
|
||||||
# Remove a database if it exists, along with the associated user
|
# Remove all existing databases associated with the app's dedicated user a database if it exists
|
||||||
ynh_psql_remove_db --db_user=$db_user --db_name=$db_name
|
sql="COPY (SELECT datname FROM pg_database JOIN pg_authid ON pg_database.datdba = pg_authid.oid WHERE rolname = '${db_user}') TO STDOUT"
|
||||||
|
dbs_to_drop=ynh_psql_execute_as_root --sql="$sql" #Fetch database(s) associated to role $db_user
|
||||||
|
|
||||||
|
if [[ -n "$dbs_to_drop" ]]; then # Check that the list of database(s) is not empty
|
||||||
|
for $db_name in $dbs_to_drop # Iterate through the list of database(s) to remove
|
||||||
|
do
|
||||||
|
if ynh_psql_database_exists --database=$db_name; then # Check if the database exists
|
||||||
|
ynh_psql_drop_db $db_name # Remove the database
|
||||||
|
ynh_print_info --message="Removed database $db_name associated to role $db_user"
|
||||||
|
else
|
||||||
|
ynh_print_warn --message="Database $db_name not found"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
ynh_print_warn --message="No associated database to role $db_user was found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove dedicated PostgreSQL role
|
||||||
|
if ynh_psql_user_exists --user=$db_user; then
|
||||||
|
ynh_psql_drop_user $db_user
|
||||||
|
ynh_print_info --message="Removed PostgreSQL role $db_user"
|
||||||
|
else
|
||||||
|
ynh_print_warn --message="User $db_user not found"
|
||||||
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# REMOVE APP MAIN DIR
|
# REMOVE APP MAIN DIR
|
||||||
|
|
Loading…
Reference in a new issue