From 6a6286888190e1efd3d265ee58658fcd6bfb089b Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 4 Jul 2026 19:01:50 -0500 Subject: [PATCH] fix(sql): purge stranded legacy remote-storage columns (MySQL 8 safe) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 02.52.25.sql used `DROP COLUMN IF EXISTS` (MariaDB-only), which errors on Oracle MySQL 8.x — so on MySQL 8 installs the 26 legacy remote_storage/ftp_*/ sftp_*/gdrive_*/s3_* columns were never dropped, yet Joomla recorded the schema as applied (confirmed on suite.dev: MySQL 8.0.41, all 26 columns still present, 0 profiles with legacy remote data). New 02.56.01 migration removes them portably: an INFORMATION_SCHEMA-gated prepared-statement ALTER that drops all 26 columns where present (plain DROP COLUMN, valid on MySQL 8 + MariaDB) and is a no-op where already gone (so it's safe on already-migrated installs too). Validated non-destructively against suite.dev (gate=1, ALTER PREPAREs cleanly). Claude-Session: https://claude.ai/code/session_01WbGBN9VyRK61zczYWcCQ2i --- .../sql/updates/mysql/02.56.01.sql | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 source/packages/com_mokosuitebackup/sql/updates/mysql/02.56.01.sql diff --git a/source/packages/com_mokosuitebackup/sql/updates/mysql/02.56.01.sql b/source/packages/com_mokosuitebackup/sql/updates/mysql/02.56.01.sql new file mode 100644 index 0000000..04a5b62 --- /dev/null +++ b/source/packages/com_mokosuitebackup/sql/updates/mysql/02.56.01.sql @@ -0,0 +1,32 @@ +-- Purge legacy single-remote storage columns from installs where they are still present. +-- +-- Background: 02.52.25.sql originally used `DROP COLUMN IF EXISTS`, which is a +-- MariaDB-only extension and errors on Oracle MySQL 8.x. On MySQL 8 installs the +-- migration failed but Joomla still recorded the schema as applied, leaving all 26 +-- legacy remote_storage/ftp_*/sftp_*/gdrive_*/s3_* columns stranded on the profiles +-- table. This migration removes them portably. +-- +-- It must be safe on BOTH engines AND on installs where the columns are already gone +-- (MariaDB, or anyone who ran the corrected 02.52.25). Plain `DROP COLUMN` errors when +-- a column is absent, and `DROP COLUMN IF EXISTS` errors on MySQL 8 — so neither works +-- unconditionally. We gate the drop on INFORMATION_SCHEMA and build the ALTER via a +-- prepared statement, which runs on MySQL 8 and MariaDB alike. All 26 columns were +-- created and dropped together, so the presence of `remote_storage` gates the whole set. +-- When the columns are absent this is a no-op (`DO 0`). + +SET @moko_has_legacy_remote := ( + SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = '#__mokosuitebackup_profiles' + AND COLUMN_NAME = 'remote_storage' +); + +SET @moko_drop_legacy_remote := IF(@moko_has_legacy_remote > 0, + 'ALTER TABLE `#__mokosuitebackup_profiles` DROP COLUMN `remote_storage`, DROP COLUMN `ftp_host`, DROP COLUMN `ftp_port`, DROP COLUMN `ftp_username`, DROP COLUMN `ftp_password`, DROP COLUMN `ftp_path`, DROP COLUMN `ftp_passive`, DROP COLUMN `ftp_ssl`, DROP COLUMN `sftp_host`, DROP COLUMN `sftp_port`, DROP COLUMN `sftp_username`, DROP COLUMN `sftp_auth_type`, DROP COLUMN `sftp_password`, DROP COLUMN `sftp_key_data`, DROP COLUMN `sftp_passphrase`, DROP COLUMN `sftp_path`, DROP COLUMN `gdrive_client_id`, DROP COLUMN `gdrive_client_secret`, DROP COLUMN `gdrive_refresh_token`, DROP COLUMN `gdrive_folder_id`, DROP COLUMN `s3_endpoint`, DROP COLUMN `s3_region`, DROP COLUMN `s3_access_key`, DROP COLUMN `s3_secret_key`, DROP COLUMN `s3_bucket`, DROP COLUMN `s3_path`', + 'DO 0' +); + +PREPARE moko_stmt FROM @moko_drop_legacy_remote; +EXECUTE moko_stmt; +DEALLOCATE PREPARE moko_stmt;