[ticket/17528] Fix MySQL platform

PHPBB-17528
This commit is contained in:
rxu 2025-06-20 14:46:39 +07:00
parent 9cccf26311
commit 98c6a88438
No known key found for this signature in database
GPG key ID: 955F0567380E586A
3 changed files with 64 additions and 0 deletions

View file

@ -149,6 +149,7 @@ class connection_parameter_factory
$enrichment_tags = [
'pdo_mysql' => [
'charset' => 'UTF8',
'platform' => new mysql_platform(),
],
'oci8' => [
'charset' => 'UTF8',

View file

@ -0,0 +1,62 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\db\doctrine;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Schema\TableDiff;
/**
* MySQL specific schema handling.
*
* While adding auto_increment column to MySQL, it must be indexed.
* If it's indexed as primary key, it ahould be declared as NOT NULL
* because MySQL primary key columns cannot be NULL.
*/
class mysql_platform extends AbstractMySQLPlatform
{
/**
* {@inheritDoc}
*/
public function getAlterTableSQL(TableDiff $diff)
{
$sql = parent::getAlterTableSQL($diff);
$table = $diff->getOldTable();
$columns = $diff->getAddedColumns();
foreach ($columns as $column)
{
$column_name = $column->getName();
if (!empty($column->getAutoincrement()) && $table)
{
foreach ($sql as $i => $query)
{
if (stripos($query, "add $column_name"))
{
if (!$table->getPrimaryKey())
{
$sql[$i] = str_replace(' DEFAULT NULL', '', $sql[$i]);
$sql[$i] .= ' PRIMARY KEY';
}
else
{
$sql[$i] .= ", ADD KEY ($column_name)";
}
}
}
}
}
return $sql;
}
}

View file

@ -18,6 +18,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\SmallIntType;