aboutsummaryrefslogtreecommitdiff
path: root/scripts/upgrade
diff options
context:
space:
mode:
authorFélix Piédallu <felix@piedallu.me>2024-05-27 13:17:03 +0200
committerFélix Piédallu <felix@piedallu.me>2024-05-27 13:31:28 +0200
commit04ee248b2dc02593a8422e955988aa5527334730 (patch)
treee2c06b79d4bfd4ddbfbb17cdb2f2f0f6d1ecbed0 /scripts/upgrade
parentf50a6703097e15472264cc4f48346763edb2bc1b (diff)
downloadmastodon_ynh-04ee248b2dc02593a8422e955988aa5527334730.tar.gz
mastodon_ynh-04ee248b2dc02593a8422e955988aa5527334730.tar.bz2
mastodon_ynh-04ee248b2dc02593a8422e955988aa5527334730.zip
Fix db_user, name when upgrading from legacy versions
Diffstat (limited to 'scripts/upgrade')
-rw-r--r--scripts/upgrade22
1 files changed, 21 insertions, 1 deletions
diff --git a/scripts/upgrade b/scripts/upgrade
index a285ff2..36ffc58 100644
--- a/scripts/upgrade
+++ b/scripts/upgrade
@@ -26,9 +26,29 @@ if [[ -z "${service:-}" ]]; then
ynh_app_setting_set --app="$app" --key=service --value="$service"
fi
-#Remove previous added repository
+# Remove previous added repository
ynh_remove_extra_repo
+if ynh_compare_current_package_version --comparison lt --version "4.2.8~ynh2"; then
+ # Rename legacy database
+ if ynh_psql_database_exists --database="${app}_production"; then
+ db_name=$(ynh_sanitize_dbid --db_name="$app")
+ ynh_app_setting_set --app="$app" --key="db_name" --value="$db_name"
+
+ # Remove the newly created db by resources, and rename legacy db
+ ynh_psql_execute_as_root --sql="DROP DATABASE IF EXISTS ${app};"
+ ynh_psql_execute_as_root --sql="ALTER DATABASE ${app}_production RENAME TO $db_name;"
+ fi
+ # Same with user
+ if ynh_psql_user_exists --user="${app}_production"; then
+ db_user="$db_name"
+ ynh_app_setting_set --app="$app" --key="db_user" --value="$db_user"
+
+ ynh_psql_execute_as_root --sql="DROP USER IF EXISTS ${app};"
+ ynh_psql_execute_as_root --sql="ALTER USER ${app}_production RENAME $db_name;"
+ fi
+fi
+
#=================================================
# STOP SYSTEMD SERVICE
#=================================================