From b4fcf41f417252e8af81b01bbf023427354fc83d Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 7 Mar 2023 09:52:10 +0100 Subject: [PATCH 1/2] delete the psql db if the migration fails --- scripts/upgrade | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/upgrade b/scripts/upgrade index da97e36..aeb0f14 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -56,6 +56,10 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # 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 } @@ -118,6 +122,7 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies 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 From 8596ecce7b28e083d53717a4d101b3bfe465b561 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 7 Mar 2023 11:42:53 +0100 Subject: [PATCH 2/2] Drop all Focalbard tables if mattermost is in 7.3.0 --- scripts/_common.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/_common.sh b/scripts/_common.sh index c73b8c3..1412e11 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -48,6 +48,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)"