1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-11 03:04:09 +02:00

[ticket/16741] Specific DBs fixes

MSSQL:
- Fix bool type
- Fix comparator
- Drop Default constraint before deleting column
- Rename Default constraint to use phpBB's names
- Re-create the indices when changing the type of one column
- Uses varchar instead of varbinary

PostgreSQL:
- Creates auto increment sequences by hand instead of using serial
  in order to use phpBB's names
- Drop constraint on unique / primary indices

Oracle:
- Rename indices to use phpBB's names
- Fix string not null behaviour
- Fix broken regex in Oracle driver
- Handle to long indices on Oracle
- Rename auto_increment trigger and sequence
- Automatically lowercase keys in assoc results

PHPBB3-16741
This commit is contained in:
Tristan Darricau
2021-11-09 03:53:52 +01:00
parent b266ebbcef
commit b8d555f56a
14 changed files with 901 additions and 12 deletions

View File

@@ -0,0 +1,139 @@
<?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\SQLServer2012Platform;
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\TableDiff;
/**
* Oracle specific schema restrictions for BC.
*/
class sqlsrv_platform extends SQLServer2012Platform
{
/**
* {@inheritDoc}
*
* Renames the default constraints to use the classic phpBB's names
*/
public function getDefaultConstraintDeclarationSQL($table, array $column)
{
$sql = parent::getDefaultConstraintDeclarationSQL($table, $column);
return str_replace(
[
$this->generate_doctrine_identifier_name($table),
$this->generate_doctrine_identifier_name($column['name']),
], [
$table,
$column['name'].'_1',
],
$sql);
}
/**
* {@inheritDoc}
*
* Renames the default constraints to use the classic phpBB's names
*/
public function getAlterTableSQL(TableDiff $diff)
{
$sql = [];
// When dropping a column, if it has a default we need to drop the default constraint first
foreach ($diff->removedColumns as $column)
{
if (!$column->getAutoincrement())
{
$sql[] = $this->getDropConstraintSQL($this->generate_doctrine_default_constraint_name($diff->name, $column->getQuotedName($this)), $diff->name);
}
}
$sql = array_merge($sql, parent::getAlterTableSQL($diff));
$doctrine_names = [];
$phpbb_names = [];
// OLD Table name
$doctrine_names[] = $this->generate_doctrine_identifier_name($diff->name);
$phpbb_names[] = $diff->name;
// NEW Table name if relevant
if ($diff->getNewName() != null)
{
$doctrine_names[] = $this->generate_doctrine_identifier_name($diff->getNewName()->getName());
$phpbb_names[] = $diff->getNewName()->getName();
}
foreach ($diff->addedColumns as $column)
{
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this));
$phpbb_names[] = $column->getQuotedName($this).'_1';
}
foreach ($diff->removedColumns as $column)
{
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this));
$phpbb_names[] = $column->getQuotedName($this).'_1';
}
foreach ($diff->renamedColumns as $column)
{
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->getQuotedName($this));
$phpbb_names[] = $column->getQuotedName($this).'_1';
}
foreach ($diff->changedColumns as $column)
{
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->column->getQuotedName($this));
$phpbb_names[] = $column->column->getQuotedName($this).'_1';
if ($column->oldColumnName != $column->column->getQuotedName($this))
{
$doctrine_names[] = $this->generate_doctrine_identifier_name($column->oldColumnName);
$phpbb_names[] = $column->oldColumnName.'_1';
}
}
return str_replace($doctrine_names, $phpbb_names, $sql);
}
/**
* Returns a hash value for a given identifier.
*
* @param string $identifier Identifier to generate a hash value for.
*
* @return string
*/
private function generate_doctrine_identifier_name($identifier)
{
// Always generate name for unquoted identifiers to ensure consistency.
$identifier = new Identifier($identifier);
return strtoupper(dechex(crc32($identifier->getName())));
}
/**
* Returns a unique default constraint name for a table and column.
*
* @param string $table Name of the table to generate the unique default constraint name for.
* @param string $column Name of the column in the table to generate the unique default constraint name for.
*
* @return string
*/
private function generate_doctrine_default_constraint_name($table, $column)
{
return 'DF_' . $this->generate_doctrine_identifier_name($table) . '_' . $this->generate_doctrine_identifier_name($column);
}
}