DbMigration: Check for mysql collation name whether to check 2.11 is migrated

This commit is contained in:
Yonas Habteab 2023-09-15 12:12:17 +02:00 committed by Johannes Meyer
parent 3f372330b3
commit 2505e79a2d
2 changed files with 32 additions and 1 deletions

View File

@ -107,6 +107,35 @@ abstract class DbMigrationHook implements Countable
return $result->column_type;
}
/**
* Get the mysql collation name of the given column of the specified table
*
* @param Connection $conn
* @param string $table
* @param string $column
*
* @return ?string
*/
public static function getColumnCollation(Connection $conn, string $table, string $column): ?string
{
if ($conn->getAdapter() instanceof Pgsql) {
return null;
}
$pdoStmt = $conn->prepexec(
'SELECT collation_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?',
[$table, $column]
);
/** @var false|stdClass $result */
$result = $pdoStmt->fetch(PDO::FETCH_OBJ);
if ($result === false) {
return null;
}
return $result->collation_name;
}
/**
* Get statically provided descriptions of the individual migrate scripts
*

View File

@ -52,7 +52,9 @@ class DbMigration extends DbMigrationHook
if (! $this->version) {
$this->version = '2.12.0';
}
} elseif (static::tableExists($conn, $schemaQuery->getModel()->getTableName())) {
} elseif (static::tableExists($conn, $schemaQuery->getModel()->getTableName())
|| static::getColumnCollation($conn, 'icingaweb_user_preference', 'username') === 'utf8mb4_unicode_ci'
) {
$this->version = '2.11.0';
} elseif (static::tableExists($conn, 'icingaweb_rememberme')) {
$randomIvType = static::getColumnType($conn, 'icingaweb_rememberme', 'random_iv');