From 755f6c399008fa2c373aefadf2f4ed2a9c3929bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Cort=C3=A9s=20Cano?= <38475681+TrapoSAMA@users.noreply.github.com> Date: Thu, 23 Jul 2026 04:31:31 -0400 Subject: [PATCH] Reconcile 3.3 MySQL upgrades on master (#1089) fix regression in MySQL database update order. See #971 thanks @TrapoSAMA and @csware --- functions.inc.php | 2 +- public/upgrade.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/functions.inc.php b/functions.inc.php index 1e6ff4bb..db49f6a9 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -16,7 +16,7 @@ */ -$min_db_version = 1851; # update (at least) before a release with the latest function number in upgrade.php +$min_db_version = 1855; # update (at least) before a release with the latest function number in upgrade.php /** diff --git a/public/upgrade.php b/public/upgrade.php index 7664f573..4c93cc82 100644 --- a/public/upgrade.php +++ b/public/upgrade.php @@ -2251,3 +2251,34 @@ function upgrade_1854() # add description after 'target_domain' field in alias_domain table _db_add_field('alias_domain', 'description', "varchar(255) {UTF-8} NOT NULL DEFAULT ''", 'target_domain'); } + +/** + * Reconcile MySQL schemas upgraded through the PostfixAdmin 3.3 branch. + * + * PostfixAdmin 3.3 used upgrade_1847_mysql() to widen quota2.username to + * varchar(255). A later upgrade to master therefore skips the more complete + * upgrade_1846_mysql() in this branch because the recorded database version + * is already 1847. The widened quota2 column is used as the marker for that + * upgrade path; a direct master upgrade leaves it at varchar(100). + * + * See https://github.com/postfixadmin/postfixadmin/issues/971 + */ +function upgrade_1855_mysql() +{ + $quota2 = table_by_key('quota2'); + $column = db_query_one( + "SELECT CHARACTER_MAXIMUM_LENGTH AS character_maximum_length + FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() + AND TABLE_NAME = :table + AND COLUMN_NAME = 'username'", + ['table' => trim($quota2, '`')] + ); + + $column_length = (int) (array_values($column ?? [])[0] ?? 0); + if ($column_length !== 255) { + return; + } + + upgrade_1846_mysql(); +}