diff --git a/phpBB/phpbb/db/doctrine/connection_parameter_factory.php b/phpBB/phpbb/db/doctrine/connection_parameter_factory.php index 740c4b82b7..90e41061fc 100644 --- a/phpBB/phpbb/db/doctrine/connection_parameter_factory.php +++ b/phpBB/phpbb/db/doctrine/connection_parameter_factory.php @@ -149,6 +149,7 @@ class connection_parameter_factory $enrichment_tags = [ 'pdo_mysql' => [ 'charset' => 'UTF8', + 'platform' => new mysql_platform(), ], 'oci8' => [ 'charset' => 'UTF8', diff --git a/phpBB/phpbb/db/doctrine/mysql_platform.php b/phpBB/phpbb/db/doctrine/mysql_platform.php new file mode 100644 index 0000000000..cd368163dd --- /dev/null +++ b/phpBB/phpbb/db/doctrine/mysql_platform.php @@ -0,0 +1,62 @@ + + * @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; + } +} diff --git a/phpBB/phpbb/db/doctrine/postgresql_platform.php b/phpBB/phpbb/db/doctrine/postgresql_platform.php index 28f846de03..754ea47a99 100644 --- a/phpBB/phpbb/db/doctrine/postgresql_platform.php +++ b/phpBB/phpbb/db/doctrine/postgresql_platform.php @@ -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;