diff --git a/scripts/_common.sh b/scripts/_common.sh index b58959d..3cd1939 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -45,6 +45,15 @@ mariadb-to-pg() { ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.Users DROP COLUMN IF EXISTS acceptedtermsofserviceid;" --database=$db_name ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS description;" --database=$db_name ynh_mysql_execute_as_root --sql="ALTER TABLE mattermost.SharedChannelRemotes DROP COLUMN IF EXISTS nextsyncat;" --database=$db_name + + # Focalboard is broken in Mattermost 7.3.0 + if ynh_compare_current_package_version --comparison eq --version 7.3.0~ynh1 + then + # Remove Focalboard tables + # Command from https://stackoverflow.com/a/1589324 + cmd=$(ynh_mysql_execute_as_root --sql="SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_schema = '$db_name' AND table_name LIKE 'focalboard_%';" --database=$db_name | tail -n 1) + ynh_mysql_execute_as_root --sql="$cmd" --database=$db_name + fi # Use pgloader to migrate database content from MariaDB to PostgreSQL tmpdir="$(mktemp -d)" diff --git a/scripts/upgrade b/scripts/upgrade index e87d511..10bf585 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -23,6 +23,24 @@ email=$(ynh_user_get_info --username=$admin --key=mail) upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Remove the PostgreSQL db in case of error during the migration. + if [ -n "$remove_psql_in_case_of_error" ]; then + ynh_psql_remove_db --db_user=$db_user --db_name=$db_name + fi + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -48,6 +66,7 @@ fi if mysqlshow | grep -q "^| $db_name "; then # Mattermost only support MySQL and PostgreSQL (not MariaDB...) # Migrate the database from MariaDB to PostgreSQL + remove_psql_in_case_of_error=1 mariadb-to-pg fi